Monday, April 29, 2013

Compiling Git on Cygwin

First off, if you aren't using Git for your version control needs, you should be. Well alright, that's a little strong -- but if you're still using a non-DVCS (aka centralized) source control system then check it out. Seriously.

Now, on to the main topic of this post. I'm currently doing as much as possible from the Cygwin environment, and so naturally I have installed the Git package and use that instead of the more common (and perfectly usable, BTW) msysGit project. Unfortunately the currently shipping Cygwin version of Git is 1.7.9. That's a few releases old, and it bit me a little when I was Googling to figure out how to set the upstream URL for an existing remote. (The syntax for that command has changed a few times.)

So I thought I'd have a go at compiling the latest sources for Git. It turned out to be quite easy, but if you follow the "recipe" here it might save you a bit of Googling:
  1. Run the Cygwin setup utility and ensure you have the following packages installed:
    • gcc
    • autoconf
    • curl
    • libcurl-devel, required for http/https support (NOTE: this is an obsolete package, you will need to uncheck "Hide obsolete packages" when selecting packages to install)
    • make
    • libiconv
    • python
    • perl
    • gettext
    • you may need libiconv-devel and cygwin32-liviconv (see Marek's comment)
  2. Clone the Git sources with git clone A couple of notes on that with respect to Git configuration:
    1.  Make sure core.autocrlf=false, otherwise you'll end up with DOS style line endings that cause the build to break.
    2. I also had a screwy http.sslcainfo property value; either unset it or point it to /usr/ssl/certs/ca-bundle.crt.
  3. From your newly cloned git repo, run the following commands:
  4. make configure
    make install
You should be able to run git --version and see something more recent than 1.7.9. (I had to open a new Cygwin console before this exact command worked, but I could run /usr/local/bin/git.exe --version.)

That's all there is to it (see, I told you it was easy). You're now running the latest version of Git. Thanks to all the folks who work on both Cygwin and Git for making this so easy.


Marek Šuščák said...

I needed to install additional cygwin packages - autoconf, libiconv-devel, cygwin32-libiconv

Thomas Wheeler said...

Marek, thanks for the feedback. I do have autoconf installed but not libiconv-devel or cygwin32-liviconv. I just pulled from the Git repo and built it successfully, so maybe there is another package I've installed which explains why I can build without needing those two.

Neil Pickles said...

I also need tcl and also needed to change command to

make -i
make -i install

as suggested here

Jehú said...

It worked like a charm, thank you very much.

David said...


Thanks for taking the time to do this. It worked almost perfectly for me.

The one suggestion I would make to clarify your instructions would be to state that you should set core.autocrlf=false before cloning the repository. I did it the other way around was getting strage script errors because everything had been converted to DOS line endings.

That might be obvious to seasoned git users, but I'm not one of those, yet...

Deleted the repository and cloned again and the build / install went through without error.


Thomas Wheeler said...

David I think I had the same problem, and fixed it before doing this writeup. Thanks for pointing it out.

Riggs Folly said...

First, thanks for this post.

I thought I would pass on my resent experience compiling git from source.

I started with a vanilla cygwin (cygwin) 1.7.25.

I also needed to install these packages in addition to the ones you mentioned, to get over some errors in the make process.

autoconf: Wrapper

I did not need to set core.autocrlf=false it worked with that param missing from my git config.

Of course one thing that is not instantly obvious is that you have to install whatever is the latest git package in the ditro so that you can clone the source code for the latest git using that version. Seems obvious when you get to that point but its a bit Chicken & Egg until the penny drops.

In answer to Neil Pickles and the nmake -i solution. I solved that issue by installing gettext-devel and libiconv-devel rather than ignoring errors.

Hope this helps the next person that finds this as much as it did me.

Jani Lakshmanan said...

I followed the instruction and installed now my git version is 1.9.0 rc3. but i need the stable version of please assist to install the stable version

Thomas Wheeler said...

Jani, I haven't personally tried this but I would expect that you can simply "git checkout v1.8.5.4" once you've cloned the Git source repository.