Creating Git Aliases

By on

I create shortcuts for everything. I create variables which act as text shortcuts, shortcuts in TextMate to generate CSS/JS/HTML, and bash scripts so I don't have to type in the same commands over and over again. So why should version control software be any different? I commit and push religiously so I create Git aliases to save myself a few keystrokes.

Sample Aliases

#make "com" alias for "commit"
git config alias.com commit

#make "co" alias for checkout
git config alias.co checkout

#make "br" alias for branch
git config alias.br branch

# When you want to see just the differences of one function in one file in two different commits
git config alias.funcdiff '!sh -c "git show \"\$1:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp1 && git show \"\$2:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp2 &&
git diff --no-index .tmp1 .tmp2"' -



These are just some sample Git aliases. You can view more detailed (and by detailed I mean brain-numbing) examples of git aliases at the Git Wiki.

Recent Features

• Create a Sheen Logo Effect with CSS

I was inspired when I first saw Addy Osmani's original ShineTime blog post.  The hover sheen effect is simple but awesome.  When I started my blog redesign, I really wanted to use a sheen effect with my logo.  Using two HTML elements and...

• Write Better JavaScript with Promises

You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

Incredible Demos

• Create a Clearable TextBox with the Dojo Toolkit

Usability is a key feature when creating user interfaces;  it's all in the details.  I was recently using my iPhone and it dawned on my how awesome the "x" icon is in its input elements.  No holding the delete key down.  No pressing it a...

• Truly Responsive Images with responsive-images.js

Responsive web design is something you hear a lot about these days. The moment I really started to get into responsive design was a few months ago when I started to realise that 'responsive' is not just about scaling your websites to the size of your...

Discussion

1. Nice! I use ci for commit though, more like Subversion. I also have di for diff, st for status and sta for stash.

2. Terry

I’m trying to get the funcdiff alias created. When I try to call it with something like:

git funcdiff “rel\path\to\file” functionName
or

both give me an error like:
fatal: Path ‘funcitonName’ does not exist in ‘sha1-2′.
fatal: Invalid object name ‘rel\path\to\file’.

I’ve Googled everywhere for anyone using this alias to see a sample syntax, but no one has one. Have you used it successfully?

3. Dan

You can make aliases for branch name, too. For example:

4. Peter

Dan, command

ruins git repo in windows. Because it overwrites “HEAD” with “head” in “.git” directory

For ones, that tried this: just rename the file back

5. Shahzeb

Very useful, thanks!

6. Thanks for the commands,
I need to know how to create an alias for paths.
For example if I need to write “git push PATH” instead of “git push gitolite@codex…”
Regards

7. [...] Creating Git Aliases [...]

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!