Home > Technology > Creating git alias

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 🙂

Advertisements
Categories: Technology Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: