ZSH alias with parameter
You can't make an alias with arguments*, it has to be a function. Your function is close, you just need to quote certain arguments instead of the entire commands, and add spaces inside the []
.
gitall() { git add . if [ "$1" != "" ] # or better, if [ -n "$1" ] then git commit -m "$1" else git commit -m update fi git push}
*: Most shells don't allow arguments in aliases, I believe csh and derivatives do, but you shouldn't be using them anyway.
I used this function in .zshrc file:
function gitall() { git add . if [ "$1" != "" ] then git commit -m "$1" else git commit -m update # default commit message is `update` fi # closing statement of if-else block git push origin HEAD}
Here git push origin HEAD
is responsible to push your current branch on remote.
From command prompt run this command: gitall "commit message goes here"
If we just run gitall
without any commit message then the commit message will be update
as the function said.