Installing Git for Windows

Sunday, November 27, 2011

Git is my version control system of choice for al my projects at home. It has a complete and powerful set of rich features which I still learn today. After a reinstall of my system, I always have troubles setting my repos up again. This post will end this once and forever by going through all necessary steps.

The first step is getting the latest version of msysgit at http://code.google.com/p/msysgit/ and install this in the following steps.

 

image

 

image

 

image

 

image

 

I don’t need any icons or Windows Explorer integration because I don’t use it. Also I don’t use Bash as my shell so don’t need to associate .sh files as well.

 

image

 

This will only add Git to your PATH environment.

 

image

 

image

 

Check if your Git is working from your console (this maybe needs a restart). If not check your path environment variable (see also below).

 

image

 

The first thing you should do is setting your username and e-mail address. This is important because every commit you make is stored with this information. If you want a separate username and e-mail per repository you can do this as well by going into the repository and omit the --global option.

 

image

 

Besides working from my console I also want to have a proper Windows Explorer integration, which makes your life so much easier sometimes. For this I choose TortoiseGit. You can get the latest version from http://code.google.com/p/tortoisegit/. Besides the Windows Explorer integration it also comes with some tools from the PuTTY family which I need anyway. The PuTTY family are a set of SSH tools which you need to connect to remote repositories.

 

image

 

image

 

image

 

image

 

image

 

image

 

Now put the bin folder of your TortoiseGit install directory in your system PATH variable by going to Control Panel > System > Advanced system settings.

 

image

 

image

 

Click on Environment Variables.

 

image

 

Edit the Path variable by appending the value with ‘;’ + installation directory + bin\ (;C:\Program Files\TortoiseGit\bin\).

 

image

 

Now when where still in the Environment Variables window we also have to set a new GIT_SSH system variable. You will have to set the value to C:\Program Files\TortoiseGit\bin\TortoisePlink.exe. This will tell Git which SSH client to use.

 

image

 

Basically you now have everything set to create a new or clone a repository, or in my case use a existing one that is already on my disc. For working with remote Git servers you may have to do some additional steps, especially if you need to write permissions. This isn’t necessary for public read-only repositories. Most Git servers work with SSH and authenticate using SSH public keys. That said Git also supports the HTTP and the Git protocol for transferring data. The later two are most used with read-only repositories.

If you for example own a repository on BitBucket or GitHub you will need to create a public and private SSH key pair. This can be done by using the puttygen.exe tool, which is also part of the TortoiseGit installation and comes from the PuTTY family.

 

image

 

Click on generate to create a public/private key pair. The private key can be protected by a password and will add a extra layer of security. This will prompts the user for the password when using the private key. Now save your public and private key by clicking on the corresponding buttons. Before you can talk with a remote server you will need to inform it with your public key. In case of BitBucket or GitHub you will have to check their website on how to accomplish that, but it’s pretty straightforward. Most of the time you can upload the public key file or paste it in some textbox (if pasting use the selected text from the window in the puttygen tool, see above “public key for pasting into openssh authorized_keys files”)

Now when you want to connect to a remote server you have to make sure your private key is loaded by the pageant.exe tool. This tool is a SSH authentication agent used by plink. You can find this tool in your installation directory of TortoiseGit. When the program is started you can find it in your task tray.

 

image

Click on the pageant icon (right bottom)

 

image

 

Click on the Add Key button and go to the location of your private key and insert your password if you had protected it.

 

image

 

The following step depends on your situation. If you have cloned or use a existing repository from disc you probably already have a remote set and you can check your connection by inspecting a remote. Check the internet on how to create new repositories and add remotes. This post is not about that.

 

image

The first command shows your registered remotes for that repository. The second shows information about a specific remote and actually tests your connection. If this fails you have done something wrong and you should check all of your taken steps. If everything went fine you’re ready to go and use Git from the console. Now because we have manually started pageant you can also use TortoiseGit from within Windows Explorer. But to make it more user friendly we have to set the location of the private key so that whenever pageant is not loaded and TortoiseGit needs it, it automatically loads it for you.

Go to your repository and right click on it and go to the settings.

 

image

 

Go to the Git > Remote section and choose the remote and add the private key and click ok.

 

image

 Now for example when you do a pull (or fetch or push) for that repository (right click on repository folder > TortoiseGit > Pull). Be sure that the Autoload Putty Key is checked. This will auto load pageant with the key provided for the chosen remote.

 

image

Unfortunately this does not work when you want to use Git from your console. In that case you will need to start pageant manually or you can use a little PowerShell script I made, which automatically executes after I logon to my account. This script will load pageant with all private key files in a given directory and child directories. Check out my blog post Automatically start Pageant with private keys in Windows for further instructions on that.

Ok last but not least when I am working in my repository and for example I want to do a pull, I don’t always want to specify from which remote and branch. Most of the times this is always the origin remote and the master branch. So in order set the default remote ”origin” to al repositories use the first command, the second command tells to merge the changes from the master branch. Again if you want to set this default per repository omit the –global option.

 

image

Now I can do a pull like this:

 

image

 

Ok that’s all. Happy gitting.

Comments are closed