Wednesday, July 20, 2011

Git: using msysgit in Windows

Git was originally develop to manage Linux kernel source.  It is widely use in Linux community.  It has porting to many platform too including Windows.

msysgit is windows porting of Git.  It is git command line utility running in command shell console.  I personally prefer using portable msysgit and set path in my home user’s environment variable.  By using portable, I may switch git version easily when new release is available.  No setup and installation is needed for portable release.

First configuration task for msysgit is set path variable in your local user account’s environment variable to include the <msysgit>/bin folder.  Git will then available whenever you start cmd shell.

ssh.exe: Password authentication

The most common ssh authentication is password authentication.  The following example shows a basic usage to access git repository via SSH:

C:\> git clone ssh:// project
Cloning into project...
<user>@<git-server>'s password:
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

You should supply a user name (e.g: alice) for ssh connection or else it may fail.

ssh.exe: Password authentication without user name

There are situation with Git that user name may not supply in git command clause.  For example, a git repository that consist of submodule have .gitmodules as follow:

[submodule "build"]
    path = build
    url = ssh://
[submodule "core"]
    path = core
    url = ssh://

As the repository is shared for team work, commit .gitmodules with user name is not practical.  The git ssh clause should not contain user name in origin repository.  Nor it should be modified to add user name in local repository.  In this case, a default user name should supply with ssh access.

To automatically supply user name to git-server, create a ~/.ssh/config file with the following entry:

  User alice

Subsequent git operation accessing ssh will use the user specify in ~/.ssh/config. This is useful when the local user name is different to ssh service user name.

ssh.exe: public key authentication

To specify the private key used for public key authentication, update ~/.ssh/config as follow:

  IdentityFile ~/.ssh/id_dsa.home
  User alice

ssh.exe: public key authentication with key agent

If a private key was protected by passphrase, each git operation accessing ssh service with the private key requires user to enter passphrase.  This is some how troublesome and will cause problem for other program like smartgit that do not prompt for passphrase.

A direct solution is using ssh key agent: ssh-agent to supply private key to ssh.  For more detail information, please refer to this article:

msysgit: public key authentication with Putty

First, follow instructions in this article: to configure putty to work with ssh.

To make msysgit work with putty as ssh client, you need a putty program: plink.exe.  Download plink.exe and keep in save location as putty.exe.

Next, create a new environment variable GIT_SSH that point to plink.exe:


You may start using git that use putty as ssh client.

There are 2 types of ssh connection with plink: using SSH server name or putty saved session.

Plink with SSH server name is limited and does not make use of extra options available in putty.  A saved putty session may consume options like pageant authentication and SSH user name for authentication.  To make git work with putty saved session, just name saved session same as  SSH server name.

Error – missing libconv-2.dll

In PortableGit-1.7.6-preview20110709.7z release, you may encounter the following errors when executing some Git commands::

The program can’t start because libiconv-2.dll is missing from your computer. Try installing the program to fix this problem.


To get rid of the error, locate <msysgit>\bin\libconv-2.dll and copy to <msysgit>\libexec\git-core.


Grigori Kochanov said...

where should ~/.ssh/config reside - in which folder?

Chau Chee Yang said...

To Grigori Kochanov: In windows, ~/.ssh/config should reside in %userprofile%/.ssh/config