As we are developers we love to automate stuff. However, I feel that our use of git is quite a manual process and takes our time. In this article, I am going to discuss how I use alias to help me. Hope this is useful to you.
Alias for add, commit and push
So we all remember the tedious commands for pushing our code to a remote git branch whenever we make any changes to our code we have to use,
git add . //To add all your changes
git commit -m "my commit" //commit the changes that are made with a message
git push //push the commit to your repo
It seems like small but it is a very tedious process once you do it over and over again. Thus, comes the following alias to do add, commit and push it all in one command
git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'
After running this command in your cmd. You can just do the following to add, commit and push your changes.
git cmp "my commit"
Alias for add and commit
However, sometimes we just need to do a local commit.
git add . //To add all your changes
git commit -m "my commit" //commit the changes that are made with a message
No worries, I am lazy too,
git config --global alias.ac "!git add -A && git commit -m "
After running this command in your cmd. You can just do the following to add and commit your changes.
git ac "my commit"
Thanks for reading, and happy coding!
Top comments (5)
I use only one alias and the rest is one keystroke away
alias git = lazygit
15 Command Line Tools which Spark Joy in Your Terminal
Jean-Michel Fayard π«π·π©πͺπ¬π§πͺπΈπ¨π΄ γ» May 6 '21 γ» 4 min read
Great.
Currently i am using this with gitbash.
---Goto---
C:/ProgramFiles/Git/etc/bash.bashrc
open this file and add your sorthand
save
re-run
---Done---
====few alias, i use frequently====
alias test='./vendor/bin/phpunit --filter='
alias pest='./vendor/bin/pest --filter='
alias dump='composer dump-autoload'
alias serve='php artisan serve'
alias oclear='php artisan optimize:clear'
alias lclear='php artisan optimize:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache'
alias fresh='php artisan migrate:fresh'
alias seed='php artisan db:seed'
alias watch='npm run watch'
alias dev='npm run dev'
alias prod='npm run prod'
alias status='git status'
alias log='git log'
alias branch='git branch -a'
alias gcm='git checkout master'
alias ga='git add .'
alias commit='git commit -m'
alias fetch='git fetch --all'
alias pushmaster='git push origin master'
Hope mine helps your awesome arsenal β€οΈ
This is very helpful. Thanks!!
I am using a Mac with Ventura 13.3.1 and I am using Bash as shell.
I tried writing
into .gitconfig manually using vim and it did not work.
Then, I tried, with vim again, slight variations of it such as using double quotes instead of single and then escaping them with
\
. None worked. Finally, I have decided to register the alias exactly as suggested in the article using thegit config
command and it worked.Interestingly the version of the alias
git config
placed into the .gitconfig file was slightly different than the one in the command as well as all those I have tried:Hope this helps someone else!