git add, commit and push commands in one?
Building off of @Gavin's answer:
Making lazygit a function instead of an alias allows you to pass it an argument. I have added the following to my .bashrc (or .bash_profile if Mac):
function lazygit() {
git add .
git commit -a -m "$1"
git push
}
This allows you to provide a commit message, such as
lazygit "My commit msg"
You could of course beef this up even more by accepting even more arguments, such as which remote place to push to, or which branch.
I ended up adding an alias to my .gitconfig
file:
[alias]
cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
Usage: git cmp "Long commit message goes here"
Adds all files, then uses the comment for the commit message and pushes it up to origin.
I think it's a better solution because you have control over what the commit message is.
The alias can be also defined from command line, this adds it to your .gitconfig
:
git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'
While I agree with Wayne Werner on his doubts, this is technically an option:
git config alias.acp '! git commit -a -m "commit" && git push'
Which defines an alias that runs commit
and push
. Use it as git acp
. Please be aware that such "shell" aliases are always run from the root of your git repository.
Another option might be to write a post-commit hook that does the push.
Oh, by the way, you indeed can pass arguments to shell aliases. If you want to pass a custom commit message, instead use:
git config alias.acp '! acp() { git commit -a -m "$1" && git push ; } ; acp'
(Of course, now, you will need to give a commit message: git acp "My message goes here!"
)
I use this in my .bash_profile
gitpush() {
git add .
git commit -m "$*"
git push
}
alias gp=gitpush
It executes like
gp A really long commit message
Don't forget to run source ~/.bash_profile
after saving the alias.