Archive

Archive for September, 2013

Creating git alias


Most of the times, we spend considerable amount of time remembering and typing very lengthy git commands to execute a task

The easy solution for this is an alias mechanism provided by GIT.

In this post, I’ll mention an easy way to create and use git aliases

1. Creating aliases

Check for ~/.gitconfig in the home directory. This file usually contains the configuration related to git like user, name, email, template fields. In this file create one more field [alias]

For example if we open ~/.gitconfig it might be as follows

[core]
editor = vim
[user]
name = Vasanth Raja Chittampally

email = a@b.com

Now add an extra filed [alias] as follows


[core]
editor = vim
[user]
name = Vasanth Raja Chittampally

email = a@b.com

[alias]

Now under this alias filed we can specify the aliases we want.

For example I want to create an alias for “log –pretty=’%C(cyan) %h %C(Yellow) %an %C(red) %b’

I would probably add this as follows


[alias]

gp = log --pretty='%C(cyan) %h %C(Yellow) %an %C(red) %b'

2. Using aliases as git commands

Once alias is created we can use this alias name as a git command as follows

git gp <commit-id>

3. Add your own aliases 🙂

Categories: Technology Tags: , , ,