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!
Bash users need to understand that alias cannot take arguments and parameters. But we can use functions to take arguments and parameters while using alias commands.
You can replace $@ with $1 if you only want the first argument. This creates a temporary function f , which is passed the arguments. Alias arguments are only passed at the end. Note that f is called at the very end of the alias.
Open ~/. bashrc file in any editor, add alias command in that file, save the file and run the `source` command to re-execute the file with added alias command.
Keeping bash alias in a different file Now you can add any aliases in your ~/. bash_aliases file and then load them into your Bash session with the source ~/. bashrc command.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With