CN

Danilo Mello

Frontend Engineer

Go Back

Working with alias on Git

Hey folks!

In order to make my life easy when I'm working, I create some alias for Git commands that I use on a daily basis. Sounds silly, but theses alias give me some valuable extra seconds when I am typing.

So I thought if it is valuable to me, it may be valuable for someone else too. That's why I'm gonna share with you today my personal alias.

Open your Terminal and the first thing you have to do, is to access the Git configuration.

git config --global --edit

The first alias you are going to create it's to add items to staged and commit at the same time. For that, I use the letter C. Use the code below to create alias.

c = !git add --all && git commit -m

The second one that I like to use is to check the status on Git, and for that one I use the letter S.

s = !git status -s

The next one is the git log, but we are going to format in a more organized and clean and away. For that we going to bring, the branch, the name of the person, the short hash, description, and date of the commit. And we are going to apply some colors too.

l = !git log --pretty=format:'%C(blue)%h%C(red)%d %C(white)%s - %C(cyan)%cn, %C(white)$cr'

Another one that I use very often, is the git amend, the combines the current commit with the previous one. Perfect for situations where you forget to add a file on the previous commit.

amend = !git add --all && git commit --amend --no-edit

I also like to create an alias to check my history of commits based on a specific word. It's perfect if you're using semantic commits, and you want to see how many specific commits you did it.

count = !git shortlog -s --grep feat

lastly it's a series of alias that help me navigate through my branches. I'm able to create, enter or delete one branch.

b = !git checkout
bc = !git checkout -b
bl = !git branch
bd = !git branch -D

And there we go! Feel free to change their name of the alias to your needs, but this is basic how I like to use it.