I try to commit and push in one command, typing something like:
gm "This is my commit message"
Which would run:
git commit -am "This is my commit message" && git push
I’ve tried this function in my .bashrc:
function gm() {
git commit -am $1 && git push
}
Which works, except for the fact that I can not type several words as commit message. I can run
gm My_Message
and it works fine, but if I type several words, like
gm This is my message
It will only run git commit -am "This" && git push. I tried using quotation marks but it returns an error. How should I configure this function to work?
You need quotes around both the place calling the function and the git command.
An alternative approach is:
But this will mean that:
(Where \t is actually a tab)
will give the commit message of:
So all the white space is collapsed.
Also, if you want to enter a more complicated and complete commit message, you might want to you
$EDITORand omit-mentirely.Also, you aren’t really using the power of distributed version control if you immediately push every commit.