Git Aliases: Adding some fun to Git

Introduction to Git Aliases

Imagem de capa

Git is a powerful, sophisticated system for distributed version control. Gaining an understanding of its features opens to developers a new and liberating approach to source code management.

How many of you know that in Git, many powerful features are hidden behind options rather than exposed as default behavior. One such feature is Git Aliases.

What are Aliases?

Git supports aliases so you can create your own commands that do all manner of Git magic. In this post, we will see a selection of the more useful (or at least entertaining) aliases.

(All of these aliases need to be configured only once with git config & then you can use them FOREVER!)

Git Shorty

All of you must be running git status more than any other git commands! And all thanks to the continuous evolution of Git over the years, Git's inline help has become very friendly.

But one of the shortcomings of Git Status is it shows very lengthy output.

For example, git status emits 13 lines to tell me that I have a couple of staged, unstaged, and untracked changes:


git shorty tells me the same thing in 3 lines! Pretty cool, isn't it?


Git Commend

Ever commit and then immediately realize you’d forgotten to stage a file? Worry no more!

git commend quietly tracks any staged files onto the last commit you created, re-using your existing commit message.

    $git config --global alias.commend 'commit --amend --no-edit'


Git It

The first commit of a repository can not be rebased like regular commits, so it’s good practice to create an empty commit as your repository root.

git it both initializes your repository and creates an empty root commit in one quick step. Next time you spin up a project, don’t just add it to version control: git it!


Git Grog

You can customize conventional git log according to your convenience.

Here's one of the simplest way (Yes, you read it correctly!) to do that:

git config --global alias.grog 'log --graph --abbrev-commit --decorate --all \
\ --format=format:"%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) \
\ - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)"'

After which you can use git grog & the output will be quite different than git log.


Other commonly used Aliases

Here are some of the most commonly used aliases which you can set for once and then use in your git bash.

    git config --global checkout
    git config --global commit
    git config --global status
    git config --global branch
    git config --global alias.type 'cat-file -t'
    git config --global alias.dump 'cat-file -p'

If you have some neat Git aliases of your own, share them in the comments.

Happy Aliasing!!