Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

#commit.sh
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?

share|improve this question
    
$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
add comment

2 Answers

up vote 7 down vote accepted

Always quote your variables! Change it to

git commit -m "$1"

and then

./commit.sh "comment1 comment2 comment3"

will work.

share|improve this answer
add comment

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:

gitpush()
{
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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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