Whenever I'm using git, I generally add, commit, and push at the same time. So I created an alias in bash to make it simpler:

alias acp='git add -A;git commit -m "made changes";git push'

How do I make it so that the I can change the commit message from "made changes" to something else while I'm running the acp command? For example:

acp "added the Timer Class" 

The above I would want to run everything that the acp command does and make "added the timer class" the commit message. How would I do that?

Thanks!

share|improve this question
up vote 8 down vote accepted

An alias cannot accept parameters, so you need to create a function:

acp ()
{
        git add -A;git commit -m "$1";git push
}

as always, store it in ~/.bashrc and source it with source ~/.bashrc.

Or better (good hint, binfalse) to avoid performing a command if the previous was not successful, add && in between them:

acp ()
{
        git add -A && git commit -m "$1" && git push
}

Execute it with

acp "your comment"

It is important that you use double quotes, otherwise it will just get the 1st parameter.

share|improve this answer
    
I'd also recommend to substitute the ; by &&. Thus, if one of the tasks fails subsequent tasks aren't executed. – binfalse Oct 14 '13 at 11:25
    
@binfalse yeah, good one. Just updated to reflect that. – fedorqui Oct 14 '13 at 11:28
    
Thanks for the help! This will really speed up my workflow. Thanks to binfalse as well. – hmir Oct 14 '13 at 11:37

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.