DEV Community

Cover image for Git aliases
Alex Georgiev
Alex Georgiev

Posted on • Originally published at devdojo.com on

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

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:

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

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 the 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. Also, feel free to share your Git Aliases or how you speed up your work when working with Git.

Support

If you've enjoyed reading this post or learned something new and would like to support me to publish more content like this one you can support me with buying me a coffee:

Buy Me A Coffee

Thank you!

Top comments (2)

Collapse
 
bobbyiliev profile image
Bobby Iliev

This is super cool! Thanks for sharing Alex!

You should contribute this as a chapter to this opensource eBook:

Open-source Introduction to Git and GitHub eBook

Collapse
 
alexgeorgiev17 profile image
Alex Georgiev

Thanks, Bobby! I will definitely look into submitting a PR to your eBook! Thanks for bringing this up!