Git From Windows

Git on Windows

(from drupal 1434 (backup) 1434 (public) )

Install Git

Install Git for Windows from . Note you just want to grab Git, not msysGit.

On Windows you must run:

git config --global core.autocrlf false

Before you clone

This stops git on Windows from changing the line endings. Without this as you clone onto a windows box files are modified when the clone is made. One of the most visible effects of this is patches failing

When you clone a repository, you will want to use the following syntax: git clone ssh://

Since Git includes an ssh.exe in its bin/ directory, you should be good to go -- but you will have to enter your ssh password whenever you git clone/pull/push/fetch, or otherwise do comparisons against the origin. If you want to set things up so you do not have to enter your password each time, read on.

Setup to use Git without passwords like Todd does

  1. Download plink.exe (google it). This is a nice, free, full-featured command link ssh client for Win32. TJ found it here

  2. Grab puttygen.exe (google it) and use it to create a public/private keypair and add the public key into your authorized keys as instructed here . Or here . Don't protect your private key with a passphrase; instead, store your keys on your Windows machine in ~/.ssh2 (or wherever) and right select on that folder. Then (at least on XP), click on the Advanced button near the folder Attributes and place a check mark next to Encrypt contents to secure data .

  3. Logon to whichever machine you ssh into and run the following commands.
    fs setacl ~/.ssh/ system:anyuser rl
    The first command changes the access rights of your .ssh folder to be readable by anyone, which is necessary because the remote side of SSH doesn't get a valid AFS token when using public/private keys. Note that this also means that your .bashrc won't execute on the remote machine before the git commands. The second command stashes your current AFS ticket so that runauth can use it

  4. Test that you can now ssh w/o a password by entering something like:
    plink.exe -2 -C -i c:\home\tannenba\.ssh2\putty.ppk "/bin/date"

  5. Now set the GIT_SSH environment variable to be gitssh.bat , which is provided below. This batch file will rewrite that command git wants to run so that runauth is used (to get an AFS token) and also so that the correct version of Git in /unsup/git is used.
    @c:\utils\sshcvs\plink.exe -2 -C -i c:\home\tannenba\.ssh2\putty.ppk %1 "/s/std/bin/runauth /unsup/git/bin/%~2"

  6. You will need to run stashticket once a month on whatever machine you ssh into.

Dealing with the line ending mess like Todd does

Unix machines and our git repo wants to see source terminated with unix-style terminations, aka just a newline. Microsoft dev studio, however, likes to terminate source code with dos-style terminations, aka a carriage-return plus a linefeed. If you aren't careful, when you commit code from windows, you will end up with messy diff that may show all sorts of lines changed that shouldn't be (just because the line termination changed), and unix users may be unhappy because they will see \r characters everywhere in the source. Yuck.

So what I do is religiously run a batch file (I call it precommit.bat ) before I add any file into the git index with the git add or the git commit -a commands. It is safe to run this batch file at any time (running it over and over isn't a problem), but important to run this batch file before adding any files into the index - just running it before you do a commit or push is too late. This batch file essentially parses the output from git status to see figure out a list of modified files, and then it runs dos2unix.exe on each file in turn. Here it is:

@echo off
REM Edit the path on the next line to point into your git clone
pushd c:\home\tannenba\condor\CONDOR_SRC
git status | findstr /C:"modified:   src/" /C:"new file:   src/" | sed.exe "s/\//\\/g" | sed.exe "s/modified:/mod ified:/" > %TEMP%\_precom.tmp
for /f "tokens=4" %%I in (%TEMP%\_precom.tmp) do (dos2unix.exe "%%I")
You will want to edit the file path at the top of the batch file, make certain environment variable TEMP is set to a writeable subdirectory, and have git.exe, sed.exe, and dos2unix.exe in your path. For sed.exe, a good one to use is the one found in CONDOR_SRC\msconfig\sed.exe . For dos2unix.exe, I attached the one I use to this wiki page below.


  • DOS2UNIX.EXE 40960 bytes added by tannenba on 2010-Oct-06 15:37:04 UTC.
    a windows command-line utility to convert a source file from dos style line endings to unix style.