Shell script helper for git commits
bash, git, shell
Solution
You must quote the variable in your script.
#!/bin/bash -e
commit_message="$1"
git add . -A
git commit -m "$commit_message"
git push
I also set "-e" so that if there are any errors, the script will exit without processing subsequent commands.
As to your second question, the `.` in the script should refer to your current working directory, as you intend. However the `-A` is causing it to add all files that have been modiied in the repo.
Problem
I'm trying to write a simple shell script that simplifies the git commit process. Instead of ``` git add . -A git commit -m "message" git push ``` I want to do `commit.sh "my commit message"` Here's what I have: ``` #!/bin/bash commit_message="$1" git add . -A git commit -m $commit_message git push ``` There's two problems with this: When the commit message includes spaces, like "my commit message", I get the following output: `error: pathspec 'commit' did not match any file(s) known to git.` `error: pathspec 'message' did not match any file(s) known to git.` So the only part of the commit message it uses is the "my" and the other parts "commit message" are left out. I think `git add .` references the location of the shell script, not the current project directory. How do I make it so that `git add .` references where I currently am in the terminal?