Wednesday, February 18, 2009

Git tab completion from Cygwin

I have been a fan of Git since starting to use it regularly and am going to give a talk on it at a tech lunch for my company in April. For the last two weeks, I have been using Git as an SVN front-end (my company has a backed-up SVN repo that I am using for SCM) while developing for a Windows target platform application. So far the experience with Git from cygwin has been a bit mixed. Another developer I am working with ran into problems with Git from cygwin (as opposed to msysgit) that I was unable to reproduce. His problem prevented him from being able to do simple commits on staged files. Bummer.

The little tidbit I wanted to document here is related to getting tab-completion of git commands working from the Cygwin bash shell. There are plenty of posts that already document how to do this, but cygwin kept complaining about having extra tokens in the shell scripts I was sourcing from my .bash_profile. After a little bit of forensic googling, I saw a post explaining that Windows line feed characters inserted by the text editor I was using on my shell scripts was causing my problem and that I should run the scripts through the d2u utility. Problem solved!

So for Windows folks running git from cygwin, here's how you get the awesomeness of tab-completion for git:

  1. Download the source for the version of git you have installed from http://www.kernel.org/pub/software/scm/git/
  2. Copy the git-completion.bash file from the contrib/ directory and paste it into your home dir -- (I renamed my file .git-completion.bash).
  3. Run that file through dlu: $:> d2u .git-completion.bash
  4. Source the file from your .bash_profile (in your cygwin home directory):
    if [ -e "${HOME}/.git-completion.bash" ] ; then
    source "${HOME}"/.git-completion.bash
    fi
  5. Restart your cygwin shell and you should be have git tab completion working. I can't say enough about how helpful tab completion is for git (or how smart the shell script is - truly is teh awesome)