🕵️‍♂️ Learning to Use Git Alias to Boost Your Productivity

Written by balastrong | Published 2023/01/18
Tech Story Tags: programming | git | git-aliases | productivity | tutorial | software-development | coding | learning-to-code

TLDRUsing aliases is a great way to avoid repeating the same git commands over and over again. The most powerful commands are usually quite long and impossible to memorize. In the video below, I show you how to set up an alias and how to use the bang operator. I'll also share with you a list of other smart aliases you might find useful.via the TL;DR App

Setting up an Alias

Repeating the same git commands over and over again can be such a waste of time! And some of the most powerful ones are usually quite long and impossible to memorize.

That’s why aliases have been introduced!

Setting up an alias is really simple, just open up a terminal and type

git config --global alias.[commandName] [long command]

For example: git config --global alias.st 'status'

In this case, if I call git st, it will give me the result of git status.

Ok, this was easy, but what about long commands such as this one?

log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

You don’t want to write it every single time, right?

Just run this:

git config —global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

And you never have to remember this long command again!

Look at how cool and colorful this log is, by just using git lg:

Understanding Aliases

If with these two examples, you agree with me that aliases are cool, let me give you some more information you should have, in order to use aliases mindfully. Later on, I’ll also share with you a list of other smart aliases you might find useful.

You can find everything in the video down below, where I also show:

  • How to easily edit aliases without setting them from terminal
  • How to use the bang operator ! (aka exclamation mark)
  • How this weird syntax is useful: "!f(){ [some commands here] }; f"
  • A list of cool aliases to set up for you

See aliases in action

You can watch the video on YouTube, or directly here from the embedded player:

https://youtu.be/Uk4GnYoQx_I?embedable=true

Also published here.


If you have some cool aliases to share, feel free to drop them here in a comment, thank you!


Written by balastrong | In love with Open Source and and knowledge sharing - I like to talk about GitHub, Visual Studio Code and Web Development. Watch me on YouTube!
Published by HackerNoon on 2023/01/18