Alias for git add, commit and push all together.

bivor

Bivor Faruque

Posted on August 9, 2022

Alias for git add, commit and push all together.

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 
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

After running this command in your cmd. You can just do the following to add, commit and push your changes.

git cmp "my commit"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

No worries, I am lazy too,

git config --global alias.ac "!git add -A && git commit -m "
Enter fullscreen mode Exit fullscreen mode

After running this command in your cmd. You can just do the following to add and commit your changes.

git ac "my commit"
Enter fullscreen mode Exit fullscreen mode

Thanks for reading, and happy coding!

💖 💪 🙅 🚩
bivor
Bivor Faruque

Posted on August 9, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Hosting on Github
tutorial Hosting on Github

August 27, 2020