Git aliases

's avatar
Alex Georgiev ・March 23, 2021
1 minute read ・Updated March 23, 2021
Git aliases

Introduction

Everyone wants to work faster, easier and one way to achieve this is to simplify their daily tasks with simple scripts or with creating aliases to run long commands that they often forget or just tired of typing them over and over again.

If you're not using any GUI for Git or using Visual Studio Code alongside Git you can definitely take advantage of the Git aliases to make things easier for you. If you want to learn how you can use Visual Studio Code with Git check out this article here:

Version control with Visual Studio Code

How to create Git Aliases

With Git you can create aliases to speed up your process and this is something really easy to configure. All you need to do is to put them in your .gitconfig file and that's it. You can set aliases for the git commands you used the most as this is basically the general idea of using aliases, to speed up your work flow. I'll list the most commonly used commands and how to set aliases for them which you can also try out if you haven't done this yet.

You can also put the aliases in your ~/.bash_profile or ~/.bashrc but I think it will be better to put them in the .gitconfig since these are git specific aliases and it will be easier for you to manage them from the .gitconfig file itself.

As mentioned we need to edit our .gitconfig file and enter the aliases there. You can open the file with your favorite text editor and put them in a new code block named [alias]

vim .gitconfig

And create the following code block:

[alias]
        st = status
        co = commit
        ch = checkout
        be = branch
        pom = push origin master
        plom = pull origin master

You can also define the aliases using the git config command directly. In order to set the aliases we've listed above you can use the following commands:

Checkout our latest product - the ultimate tailwindcss page creator 🚀
git config --global alias.st status
git config --global alias.co commit
git config --global alias.ch checkout
git config --global alias.br branch
git config --global alias.pom = push origin master
git config --global alias.plom = pull origin master

Conclusion

This is pretty much how you can set Git aliases via the .gitconfig file or using the git config command. The process is pretty simple but same as the BASH aliases it's really useful and you can easily speed up your daily Git tasks.

I hope that you enjoyed reading this and find it useful as well.

Still have a question?

Get help or discuss anything development/design related.

Start a discussion