DRINKING THE GIT KOOL AID - GLASS 3 - ALIASES

So hopefully you've been using command line git for a few days.

Typing 'git status' and 'git difftool' over and over is a royal pain huh?

Turns out there is an easy solution!

Git aliases...

Open up your .gitconfig file we talked about in our last post and add the following:

[alias]
    st = status
    ci = commit
    co = checkout
    dt = difftool

Now simply type 'git st' (it is 4 less characters!)

Another command you'll frequently use is 'git log' to see who changed what, etc.

While the default is useful there are lots of ways you can format it:

[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ (%cr)[%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --numstat
lm = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ (%cr)[%cn]" --decorate --author jpriest
standup = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --since yesterday --author jpriest

Note: Change my username to yours in the examples above.

Try these out and then hit the Google for more useful aliases. There are a ton out there you can copy and as you become more familiar with the available Git commands you can also add more of your own.

Published on Thursday, July 04 2013    

COMMENT / SHARE

Comments disabled for this post. Still want to bug me about it? Hit me up on one of the social sites listed to the right.

About

Jim is a Senior Applications Engineer working at Red Hat. He slso likes motorcycles and keeping his quadcopter out of trees.