A Note on the Series:
Fast Fridays 🏎 is a series where you will find fast, short and sweet tips/hacks that you may or may not be aware of. I will try to provide these (fairly) regularly on Fridays.
An alias is simply a shortcut that can reference a longer command. When an alias is configured, git will substitute the alias with the command that it is mapped to. Setting up aliases for common git commands can speed up your workflow and efficiency as you will spend less time typing or trying to remember full commands.
Aliases can be set up in two different ways:
- Using the
- Directly editing the git config files in your
I would recommend going with option #1. I find this to be the fastest way to set things up so that will be the method I discuss. However, feel free to do whatever works best for you.
Let's say you wanted to set up aliases for three common git commands:
status. To configure those aliases you would run the following in your terminal:
git config --global alias.br branch git config --global alias.co checkout git config --global alias.st status
If you view the
.gitconfig file in your home directory you should now see this:
[alias] br = branch co = checkout st = status
If you want to add a git alias for commands that have spaces, wrap the command in double (
"") or single (
git config --global alias.undo "reset --hard"
The next time you want to run any of those commands, you can now utilize the aliases you just set up! For example,
git br will now execute the same operation as
git branch and
git undo will now execute
git reset --hard.
El Fin 👋🏽
With a few simple short steps, you can quickly improve your git workflow. The examples I provided are some of the aliases I use but there tons more options that you can easily configure. Thanks for reading and happy coding!