Work more efficiently with using alias of git

Hi there! Do you use git?

Nowadays git is indispensable tool for development of applications. I guess you run git command many times a day.
In this blog, I introduce how to make configuration of alias of git in order to make git command shorter.

For example, we assume you take 60 seconds to type git command a day. If we can make it 30 seconds with alias, we can save 150 seconds a week, 10 minutes a month and 2 hours a year!

Let's make config of alias!

We can make config of alias on .gitconfig. We can commit this file on remote repository but it may depend on the taste of each developers so it may better to set it on your local.

How to set

Here's an example.
$ vim ~/.gitconfig
    name = kakeyang
    email = kakeyan****
    editor = vim
    s  = status
    ss = status -s
    sh = show

In this example, we can run commands like this below.
git s => git status
git ss => git status -s
git sh => git show

Recommendation of alias

Here's the recommendation of alias configuration.

Alias with alias command

In order to confirm the configuration of alias, we can define alias named alias.
    alias = !git config --get-regexp '^alias\\.' | sed 's/alias\\.\\([^ ]*\\) \\(.*\\)/\\1\\\t => \\2/' | sort
Then you can display the list of alias configs with running git alias command.
$ git alias

Show pretty logs

    ta = log --graph --branches --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(green)- %an, %cr%Creset'

It's possible to modify format of git log with using --pretty option.
Then you can run git l command.
$ git l

Here's one more recommended alias. We can see modified files and lines with it.
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat

Then you can run
$ git ll

Pull which can rebase

If we use git pull command as it runs, your modified files on your local repository can be merged. If we add --rebase option, git executes not merge but rebase and we can keep the latest modified files on our local.

    rb = pull --rebase

git pull --rebase is convenient but bored to run it many times. But we just run git rb if we set this above.

$ git rb

Synchronize remote and local branch

We occur much difference between remote and local when we develop. In this case we can run git refresh command.

    refresh= !git fetch origin && git remote prune origin

This is for removing branch information on local with using prune, and to keep the remote branch information latest. This is very convenient.


This is the blog of our friend and we recomment do refer it too!
7 Tips For Contributing To Open Source Projects On Github For Beginners
If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Tomohide Kakeya

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


Post a Comment