Pimp my git

Now that I’m starting to use git more regularly I’ve started looking for ways to make git even better. It turns out that git’s really easy to customise.

Aliases

Having recently heard that “git stage” is going to be added as an alias for “git add” another git fan mentioned that you can add your own git aliases to the .git/config file. I particularly like this idea as some of the commands can be a little bit esoteric. To get you started try adding this entry to your .git/config file.

[alias]
  stage = add
  unstage = reset HEAD

Now you can add content to the staging area using

  git stage new_file

and then remove it again using

  git unstage new_file

Pretty log

This one’s an alias, just add it in the same way as stage/unstage

plog = log --pretty=tformat:'%h %Cblue%cr%Creset %cn %Cgreen%s%Creset'

I find this format much easier to read, colour coded information and you can fit lot’s more commits on screen. This makes the graph version of log awesome, take a look

git plog --graph

Win!

Colour coded status

Add the following to .git/config and staged files will be shown in green, unstaged in red.

[color]
  ui = auto

Command line prompt

The git-prompt project will let you customise your prompt to include all sorts of git information, the defaults are a bit full on but you can tame it to your taste easily enough

I’m sure I’ll keep adding to this list, let me know any great git tricks you’ve got.


 
 
 

6 Responses to “Pimp my git”

  1. ervandew
    25. June 2009 at 17:06

    You may want to use ‘tformat’ instead of ‘format’ so that the proper newline is added to the final entry of the log output:

    plog = log –pretty=tformat:”%h %Cblue%cr%Creset %cn %Cgreen%s%Creset”

  2. Kevin Ballard
    25. June 2009 at 22:45

    The contrib/ directory in the git.git repo has a bash completion script which also provides a tool for enhancing your bash prompt.

  3. opsb
    26. June 2009 at 02:22

    @ervandew I didn’t know about tformat, I’ve updated the post, cheers
    @Kevin I’ll have to take a closer look at the git.git repo, I hadn’t realised that there were additional resources in there.

  4. Carl
    7. July 2009 at 01:07

    I get this when I do git plog. Any idea?

    fatal: ambiguous argument ‘%Cblue%cr%Creset’: unknown revision or path not in the working tree.
    Use ‘–’ to separate paths from revisions

  5. Dwight Holman
    13. July 2009 at 16:51

    You can fix the ambiguous argument error by using single quotes around the format string in the alias.

  6. Internet Banking
    4. February 2010 at 04:15

    Hey, I just hopped over to your site via StumbleUpon. Not somthing I would normally read, but I liked your thoughts none the less. Thanks for making something worth reading.

Leave a Reply