In order to make uploading the code to github easily, I created a sh script

git add .
git commit -m $1
git push origin master

But when I run it by saying ./commit.sh "comment1 comment2 comment3" , I get the error of:

error: pathspec 'comment2' did not match any file(s) known to git.
error: pathspec 'comment3' did not match any file(s) known to git.

What's wrong and how do I make it work?

  • $2 is comment2, $3 is comment3 – Melon Mar 11 '13 at 11:19
  • how do I make it work? – Alex Malex Mar 11 '13 at 11:25
  • Removed my comment. Timo Kluck answer works, just checked it. – Melon Mar 11 '13 at 13:37

Always quote your variables! Change it to

git commit -m "$1"

and then

./commit.sh "comment1 comment2 comment3"

will work.

| improve this answer | |

You could combine several commands in one line.

git add . && git commit -m "Your commit message" && git push origin master

which is a nice line to use as a command:

git add . && git commit -m "$1" && git push origin master

If you place that command in your .bash_aliases file, you can use it as follows:

gitpush "finally fixed that long-standing bug"

This command will work when every step of it works.

| improve this answer | |
  • I must note that git commit -a is not the same as git add . && git commit, as git add . doesn't remove files from the index, although git commit -a will stage all changes before commit. – Dan Mar 11 '13 at 12:08
  • how do I use gitpush()? Where do I create it and how do I call it? – Alex Malex Mar 11 '13 at 12:31
  • @Dan You are right, let me stick to expressing everything. – don.joey Mar 11 '13 at 12:42
  • Hi Alex, I have edited the answer to say you should put in, for instance, in .bash_aliases file. Check howtogeek.com/73768/… If needed, log out and back in. – don.joey Mar 11 '13 at 12:47
  • @Private You still need to remove the a option from git commit so it becomes the same as the OP's request ;) – Dan Mar 11 '13 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.