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

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

  • By
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

Incredible Demos

  • By
    GitHub-Style Sliding Links

    GitHub seems to change a lot but not really change at all, if that makes any sense; the updates come often but are always fairly small. I spotted one of the most recent updates on the pull request page. Links to long branch...

  • By
    Send Email Notifications for Broken Images Using jQuery AJAX

    It's usually best to repair broken image paths as soon as possible because they can damage a website's credibility. And even worse is having a user tell you about it. Using jQuery and PHP, you can have your page automatically notify you of broken...

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
    git funcdiff HEAD~2 HEAD “rel\path\to\file” functionName

    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:

    git symbolic-ref head HEAD

  4. Peter

    Dan, command

    git symbolic-ref head HEAD

    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

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