Wednesday, June 11, 2008

Getting started with Git on Windows

Although I'm familiar with and like subversion, I need to find a distributed source code management system, and spent some time looking into them, particularly using the info in the wikipedia article. The three most interesting systems seem to be git, bazaar, and mercurial. I decided that git would be the most mature, as it is used for managing the linux kernel development.

I had a few issues getting started, so I thought I'd describe them here in case it helps anyone else.

I decided to download the 1.5.5 preview from Google Code. The installation was very simple, so time to start working through the tutorial-ish manual.

The first step was to clone an existing repository. I decided that I'd want the eclipse plugin, so I chose egit. After trying a few variations of the checkout command, I decided that my proxy/firewall was a problem, and looked into how to get around this problem. It was unlikely that my proxy would allow the git:// protocol, so I looked into using http.

In the Git Bash, I tried using
$ git config --global http.proxy proxyname:port
but it didn't work. So I tried
$ git config --global http.proxy http://proxyname:port
that didn't work. I tried
$ export http_proxy=http://proxyname:port
and this time it (the clone operation) did work. The clone command that I used was
$ git clone http://repo.or.cz/r/egit.git egit

Note the "/r/" in the URL there. The egit page has slightly different paths:
http://repo.or.cz/w/egit.git - the home page
git://repo.or.cz/egit.git - the git: URL
http://repo.or.cz/r/egit.git - the http: download URL
I don't know if that's a standard feature of these systems, but it did slow me down!

Then, I went on to the second subsection of the manual, "How to check out a different version of the project". The command
$ git checkout -b new v0.2
failed with:
error: Entry 'org.spearce.egit-feature/.settings/org.eclipse.core.runtime.prefs' not uptodate. Cannot merge.

After some searching, I found roughly what this message means. Noticing a suggestion elsewhere in the manual advice to try gitk, I discovered that there were "Local uncommitted changes, not checked into index" as suggested by the error. But I hadn't made any changes. I remembered the Important Compatibility Notice from the installation procedure warning me of an autocrlf issue that had changed recently. The diff aspect of gitk didn't really demonstrate whether this was the issue, but I tried removing the repository, setting core.autocrlf false, and then cloning it again. This time, gitk didn't identify any local uncommitted changes, and creating a new branch worked.

It's a bit hard to work out how the config business works. At the moment, if I try to find out all the config settings, I get a list that includes two values of core.autocrlf:
$ git config -l
core.symlinks=false
core.autocrlf=true
color.diff=auto
pack.packsizelimit=2g
gui.recentrepo=C:/Documents and Settings/jyesberg/...
http.proxy=http://proxyname:80
core.autocrlf=false
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
remote.origin.url=http://repo.or.cz/r/egit.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master


I tried the following commands to remove the first line, but none seemed to work:
$ git config --global core.autocrlf false
$ git config core.autocrlf false
$ git config --unset-all core.autocrlf

The final command removed the second variable, but not this sticky first one. But perhaps the first one isn't being used. I decided to edit (with vi) the global config file (.gitconfig) directly in case it was a safer option. To be sure that I was in the right directory, I started a new Git Bash (from the Start menu). That first value is still there, but seems not to be a problem.

I thought it would be nice to make some mods to the manual to provide this advice, and (after guidance from the mailing list) it seems I need to git git. Unfortunately, although
$ git clone http://www.kernel.org/pub/scm/git/git.git
always seems to start, and go through dozens of gets and walks, it always seems to fail, either by freezing or with an error message:
error: Unable to find 1f405709e7341c27e20c0159fb7c17efbf85975c under http://www. kernel.org/pub/scm/git/git.git
Cannot obtain needed blob 1f405709e7341c27e20c0159fb7c17efbf85975c
I'm not sure how to get past this barrier - maybe I'll get some help from the list.

Update:
From my home computer, I was able to git git with http, so perhaps it had been the work proxy that had been causing (or contributing to) the problem. Out of interest, I also tried using the git protocol, and it was at least twice as fast (approx 2 mins instead of 5 mins) although I wasn't timing carefully.

5 comments:

Anonymous said...

I came across the same problem you had.

I was trying "git config --global --unset core.autocrlf" but with no effect. However, I found that core.autocrlf was mentioned when I ran "git config --system --list" but not when I ran "git config --global --list". Similarly, I found autocrlf mentioned in C:\Program Files\Git\etc\gitconfig but not in C:\Documents and Settings\A.Grimm\.gitconfig . So it must be a system variable, not a global variable. Running

git config --system --unset core.autocrlf

managed to fix the problem, without needing to use a text editor.

Валерий said...

"export http_proxy" and use git bash works fine for me! Thanks for help.

P.S.
Git bash load environment variables form Windows environment variables, so you can set http_proxy in Windows and always be set in Gyt Bash

Валерий said...

Set variable "http_proxy" work fine for all git tools, witch work over git.exe: git.cmd, gitk.cmd, Git Extension and Tortoise Git!

SteveS said...

This helped a lot! Thaks

This was confusing to me because --system and --global are synonomous to me, apparently global means global per user, because
on Windows 7 the folders accessed are as follows
git config --system --list (accesses system wide system-wide configuration file at \Program Files\Git\etc\gitconfig


$ git config --global --list (accesses global (per user) config file at \Users\Username\.gitconfig on Windows (note DOTgitconfig) )

Николай Мишин said...

thanks
"export http_proxy" and use git bash works fine for me!