Creating a Shell Script that deletes specified files in git repo
Clash Royale CLAN TAG#URR8PPP
How would I create a script that would take a list of file names in a git repository (I was planning on using a .txt file with one file name on each line, but I am open to other suggestions) as an input, and then remove those specified files from the repository?
I was thinking about using the 'cat' command and a pipe, so that in the terminal the commands would look something like this:
cd my-git-repo
cat fileNames.txt | myShellScript.sh
git push origin master
And then 'myShellScript.sh' would be:
#!/bin/bash
git rm $0
git add .
git commit -m "removed unused file"
Also I know there should be some type of 'read' command to read fileNames.txt line by line, but I am confused by what the syntax of it should be in this context.
I am fairly new to Unix/git so if this is not a feasible way to try and do this, or if there is a much better way of doing it, I would really appreciate being pointed in the right direction.
bash shell-script shell git
add a comment |
How would I create a script that would take a list of file names in a git repository (I was planning on using a .txt file with one file name on each line, but I am open to other suggestions) as an input, and then remove those specified files from the repository?
I was thinking about using the 'cat' command and a pipe, so that in the terminal the commands would look something like this:
cd my-git-repo
cat fileNames.txt | myShellScript.sh
git push origin master
And then 'myShellScript.sh' would be:
#!/bin/bash
git rm $0
git add .
git commit -m "removed unused file"
Also I know there should be some type of 'read' command to read fileNames.txt line by line, but I am confused by what the syntax of it should be in this context.
I am fairly new to Unix/git so if this is not a feasible way to try and do this, or if there is a much better way of doing it, I would really appreciate being pointed in the right direction.
bash shell-script shell git
1
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04
add a comment |
How would I create a script that would take a list of file names in a git repository (I was planning on using a .txt file with one file name on each line, but I am open to other suggestions) as an input, and then remove those specified files from the repository?
I was thinking about using the 'cat' command and a pipe, so that in the terminal the commands would look something like this:
cd my-git-repo
cat fileNames.txt | myShellScript.sh
git push origin master
And then 'myShellScript.sh' would be:
#!/bin/bash
git rm $0
git add .
git commit -m "removed unused file"
Also I know there should be some type of 'read' command to read fileNames.txt line by line, but I am confused by what the syntax of it should be in this context.
I am fairly new to Unix/git so if this is not a feasible way to try and do this, or if there is a much better way of doing it, I would really appreciate being pointed in the right direction.
bash shell-script shell git
How would I create a script that would take a list of file names in a git repository (I was planning on using a .txt file with one file name on each line, but I am open to other suggestions) as an input, and then remove those specified files from the repository?
I was thinking about using the 'cat' command and a pipe, so that in the terminal the commands would look something like this:
cd my-git-repo
cat fileNames.txt | myShellScript.sh
git push origin master
And then 'myShellScript.sh' would be:
#!/bin/bash
git rm $0
git add .
git commit -m "removed unused file"
Also I know there should be some type of 'read' command to read fileNames.txt line by line, but I am confused by what the syntax of it should be in this context.
I am fairly new to Unix/git so if this is not a feasible way to try and do this, or if there is a much better way of doing it, I would really appreciate being pointed in the right direction.
bash shell-script shell git
bash shell-script shell git
edited Feb 22 at 18:14
Degnan
asked Feb 21 at 21:48
DegnanDegnan
11
11
1
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04
add a comment |
1
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04
1
1
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04
add a comment |
1 Answer
1
active
oldest
votes
You can deploy your code from a git repo with rsync
. A file e.g. exclude-rsync.txt
could contain all files and directories (one per line) you don't want to deploy to the target (could be a new directory, too).
exlude-rsync.txt
.git
.gitignore
include/database.yml
rsync command
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
CI / CD pipelines
With gitlab, travis ci (& jenkins) you can define ci/cd piplines usually in a yaml file. Whenever something is pushed to git(lab) or a branch is merged to master, the pipeline will start automatically. For gitlab you would add a file called .gitlab-ci.yml
and it could look like this:
stages:
- deploy
deploy_production:
stage: deploy
environment: production
only:
- master@my_repo
before_script:
- yum -y install rsync
script:
- |
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
But in a simpler case you would add a shell file e.g. deploy.sh
having in mind that those pipelines exist and it might be good practice.
#!/bin/bash
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502182%2fcreating-a-shell-script-that-deletes-specified-files-in-git-repo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can deploy your code from a git repo with rsync
. A file e.g. exclude-rsync.txt
could contain all files and directories (one per line) you don't want to deploy to the target (could be a new directory, too).
exlude-rsync.txt
.git
.gitignore
include/database.yml
rsync command
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
CI / CD pipelines
With gitlab, travis ci (& jenkins) you can define ci/cd piplines usually in a yaml file. Whenever something is pushed to git(lab) or a branch is merged to master, the pipeline will start automatically. For gitlab you would add a file called .gitlab-ci.yml
and it could look like this:
stages:
- deploy
deploy_production:
stage: deploy
environment: production
only:
- master@my_repo
before_script:
- yum -y install rsync
script:
- |
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
But in a simpler case you would add a shell file e.g. deploy.sh
having in mind that those pipelines exist and it might be good practice.
#!/bin/bash
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
add a comment |
You can deploy your code from a git repo with rsync
. A file e.g. exclude-rsync.txt
could contain all files and directories (one per line) you don't want to deploy to the target (could be a new directory, too).
exlude-rsync.txt
.git
.gitignore
include/database.yml
rsync command
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
CI / CD pipelines
With gitlab, travis ci (& jenkins) you can define ci/cd piplines usually in a yaml file. Whenever something is pushed to git(lab) or a branch is merged to master, the pipeline will start automatically. For gitlab you would add a file called .gitlab-ci.yml
and it could look like this:
stages:
- deploy
deploy_production:
stage: deploy
environment: production
only:
- master@my_repo
before_script:
- yum -y install rsync
script:
- |
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
But in a simpler case you would add a shell file e.g. deploy.sh
having in mind that those pipelines exist and it might be good practice.
#!/bin/bash
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
add a comment |
You can deploy your code from a git repo with rsync
. A file e.g. exclude-rsync.txt
could contain all files and directories (one per line) you don't want to deploy to the target (could be a new directory, too).
exlude-rsync.txt
.git
.gitignore
include/database.yml
rsync command
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
CI / CD pipelines
With gitlab, travis ci (& jenkins) you can define ci/cd piplines usually in a yaml file. Whenever something is pushed to git(lab) or a branch is merged to master, the pipeline will start automatically. For gitlab you would add a file called .gitlab-ci.yml
and it could look like this:
stages:
- deploy
deploy_production:
stage: deploy
environment: production
only:
- master@my_repo
before_script:
- yum -y install rsync
script:
- |
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
But in a simpler case you would add a shell file e.g. deploy.sh
having in mind that those pipelines exist and it might be good practice.
#!/bin/bash
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
You can deploy your code from a git repo with rsync
. A file e.g. exclude-rsync.txt
could contain all files and directories (one per line) you don't want to deploy to the target (could be a new directory, too).
exlude-rsync.txt
.git
.gitignore
include/database.yml
rsync command
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
CI / CD pipelines
With gitlab, travis ci (& jenkins) you can define ci/cd piplines usually in a yaml file. Whenever something is pushed to git(lab) or a branch is merged to master, the pipeline will start automatically. For gitlab you would add a file called .gitlab-ci.yml
and it could look like this:
stages:
- deploy
deploy_production:
stage: deploy
environment: production
only:
- master@my_repo
before_script:
- yum -y install rsync
script:
- |
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
But in a simpler case you would add a shell file e.g. deploy.sh
having in mind that those pipelines exist and it might be good practice.
#!/bin/bash
rsync -avz --delete --exclude-from=exclude-rsync.txt . foo@192.168.0.123:/var/www/foobar/
answered Feb 21 at 22:41
Michael D.Michael D.
1,707816
1,707816
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502182%2fcreating-a-shell-script-that-deletes-specified-files-in-git-repo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Have you attempted anything so far? This question as written is probably too broad. Your question would be much better received if you attempted to write it (even if it's a poor attempt) and then asked question(s) here about any specific problem(s) you encounter. I definitely recommend creating a test repository to work with though in order to avoid unintentionally deleting the wrong data.
– Jesse_b
Feb 21 at 22:04