Making Git Commands A Little Shorter

Posted by jeff Thursday, June 11, 2009 00:13:00 GMT

Most of you git geeks probably already knew this, but recently I learned how to make git a little more usable for me.

One of the things I appreciate about Subversion’s command line interface is that, usually, you don’t have to type the entire command name. As long as you enter enough of the command so it can’t be confused with another subversion command, it will work.

For example, instead of doing:

svn status

I always do

svn st

(i know, I know, you can go even further and create shell aliases that are even further, or shell scripts, or whatever…)

Anyway, now that I’m using git for my personal projects, I end up doing this a lot:

git status

But recently I learned that I can make this shorter by creating a git alias for the status command (or any other command I want).

So I did this:

git config alias.st status

Now I can do this instead:

git st

You can do the same for git commit:

git config alias.ci commit

For more information about how to create aliases in git, well… just Google for it. You’ll be glad you did.

Comments

Leave a response

  1. Tore Darell   June 11, 2009 @ 12:36 PM

    And if that’s not short enough, you can add even shorter aliases to ~/.bashrc:

    # git aliases
    alias gs='git status'
    alias gb='git branch -a --color'
    alias gd='git diff --color'
    alias gc='git commit -e'
    alias ga='git add'
    alias gl='git log'
    alias gps='git push'
    alias gpl='git pull'
    alias gco='git checkout'

    Very practical when you spend the entire day using these commands :)

  2. Josh Nichols   June 11, 2009 @ 03:34 PM

    You probably want to use ‘git config—global’ for aliases. Otherwise, it will only be saved in your current repo’s .git/config, rather that ~/.gitconfig. Of course, having per-project aliases could be useful, but I haven’t thought of a use case for that yet.

  3. warren vosper   June 11, 2009 @ 05:13 PM

    I love using git-sh:

    http://github.com/rtomayko/git-sh/tree/master

    not quite as short as the aliases above but you can leave off the ‘git’ part at least.

  4. florida websites   June 14, 2009 @ 10:36 PM

    I have the most confusing time trying to understand subversion. Does anybody here think that Git is easier to pick up? I hope so.