GIT (SSH) with Visual Studio

It’s quite tricky to make Visual Studio to work with GIT repository as by default Microsoft is pushing its own product Team Foundation Server. But anyway Microsoft lets the possibility to work with GIT in Visual Studio… but only using SSL communication between repository and IDE. To make it work with SSH you should do more steps than just to install Visual Studio. Here are some steps that can be useful when you’d like to work with GIT using Visual Studio.

In this article we’ll be using following tools:

  1. Visual Studio 2013 Pro
  2. GIT
  3. TortoiseGIT version control
  4. Source Tree software

Install GIT

Before start working with GIT repository we should install local version of GIT server which will manage your local GIT repository and provide you with tools such keys generation and basic tools to work with local and remote repositories.

To install GIT on Windows:

  1. Download GIT from http://git-scm.com/
  2. Once downloaded run the installation
    1. Welcome screen (Figure 1).

      Figure 1
      Figure 1
    2. Accept license and terms conditions (Figure 2).

      Figure 2
      Figure 2
    3. Select installation destination folder (Figure 3).

      Figure 3
      Figure 3
    4. Select which context menu type you’d like to use. Select advanced to have all features (Figure 4).

      Figure 4
      Figure 4
    5. Choose create or not Start Menu Folder shortcut (Figure 5).

      Figure 5
      Figure 5
    6. Select if to add GIT bin folder path to your PATH environment variable. Select first option if you will use GIT command line only from BIN folder of GIT. Select the second one if you’d like installer to add this path to your environment variable automatically. Check “Add GIT to Windows PATH environment variable” here below if you choose first option to install (Figure 6).

      Figure 6
      Figure 6
    7. Select how GIT will manage files and folders checkout. Leave default recommended first option if not sure about implications (Figure 7).

      Figure 7
      Figure 7
    8. Wait to be installed (Figure 8).

      Figure 8
      Figure 8

Click finish once installation is complete (Figure 9).

Figure 9
Figure 9

Add GIT to Windows PATH environment variable

If you’ve chosen edit PATH environment variable by yourself you should follow these steps to be able to access GIT from command prompt.

To edit this variable:

  1. Go to “This PC”->”Properties” by mouse right clicking or “windows” + “break” key combination.
  2. Select “Advanced system settings”. Enter your credentials in case you’ve been asked. Note, that you should be administrator of the machine or be logged as an administrator in order to be able to edit this setting (Figure 10).

    Figure 10
    Figure 10
  3. Select “Environment variable” to edit variable (Figure 11).

    Figure 11
    Figure 11
  4. In opened dialogue find “path” variable in “system variables” section. Click edit (Figure 12).

    Figure 12
    Figure 12
  5. Append in the end of “Variable value” field path to BIN folder of GIT (Default C:\Program Files (x86)\Git\bin). Click OK to save (Figure 13).

    Figure 13
    Figure 13
  6. Restart of PC is required to make take it into account.

Generate keys

After restarting your PC you should be able to access GIT in command line. Open Command prompt and type “git help -a” to list all available commands of GIT. In case you variable is set right you should be able to see this list.

Before continuing with GIT you should create your personal SSH keys which will be used for authentication against GIT remote repository provided by your administrator or online.

To generate new key

  1. Log in to your local computer as an administrator.
  2. In a command prompt, run: ssh-keygen -t rsa -C “label of the key” (Figure 14).

    Figure 14
    Figure 14
  3. Enter path where to save key. Note, that the last name specified is the name of the key and not the folder. (Figure 15).

    Figure 15
    Figure 15
  4. Enter you passphrase which will be used to encrypt the key. Note, the passphrase is not shown when you type in command prompt. Be careful when typing.
  5. Confirm you passphrase.

NOTE: Do not FORGET your passphrase as this will be used latter when proceed with settings.

On figure 16 you can see the result of the key generation.

Figure 16
Figure 16

Now you can exit command prompt.

Install TortoiseGIT

You can download TortoiseGIT from https://www.google.be/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=tortoisegit.

  1. Download the latest version of TortoiseGIT source control. Select version of OS you are using x86 or x64.
  2. Install TortoiseGIT.

Generating PPK keys to be used by PuTTY

Once source control is installed we can proceed with configuration. Now we need to create PPK keys from previously generated SSH key. To do this:

  1. Go to TortoiseGIT installation BIN folder. Default is “C:\Program Files\TortoiseGit\bin\”.
  2. Open “puttygen.exe” (Figure 17).

    Figure 17
    Figure 17
  3. In opened window select “Conversions”->”Import Key” in menu bar (Figure 18).

    Figure 18
    Figure 18
  4. Select PRIVATE key generated previously by ssh-keygen (Figure 19).

    Figure 19
    Figure 19
  5. Enter passphrase specified while creating key (Figure 20).

    Figure 20
    Figure 20
  6. Enter “Key comment” as a key identification label (Figure 21).

    Figure 21
    Figure 21
  7. You can edit passphrase or leave it as it is. In case you leave the passphrase as it is this will be the same as you specified while creating SSH key with ssh-keygen. If you choose to change passphrase, note this one and DO NOT FORGET this as this will be used to connect to repository (Figure 22).

    Figure 22
    Figure 22
  8. Click “Save public key” to save public PPK key.
  9. Click “Save private key” to save private PPK key.
  10. You should now have four keys in your folder (Figure 23).

    Figure 23
    Figure 23

You can exit PuTTY Key Generator.

Install Visual Studio plugins

After source control is installed we can start to configure Visual Studio. This consists in installation of Visual Studio plugins for TortoiseGIT.

TGIT

  1. Open Visual Studio IDE.
  2. In Menu select “TOOLS”->”Extensions and Updates”.
  3. Select “Online”->”Visual Studio Gallery” in the left pane.
  4. In search find in the top right corner type “TGIT” to find TortoiseGIT plugin.
  5. Install plugin.

If you plan to install other plugins you can do not restart Visual Studio. Once all plugins will be installed you can restart Visual Studio IDE.

GitFlow

This plugin lets you easy create branches and releases. To download this plugin repeat steps from TGIT installation by finding “GitFlow” in search field.

 Add keys to TortoiseGIT

To add private key to TortoiseGIT you should clone remote repository to your local system.

  1. Bring context menu of the TortoiseGIT in folder where you’d like to clone remote repository (Figure 24).

    Figure 24
    Figure 24
  2. Select “Clone” option.
  3. In opened window
    1. Set URL of remote repository.
    2. Set destination folder
    3. Check “Load Putty Key” checkbox to load private PPK key generated in previous steps.
    4. Browse for the key (Figure 25).

      Figure 25
      Figure 25
    5. Click OK to save.
    6. Enter passphrase of the private key.

Click OK when clone is finished.

Andrew Adamich

Advertisements

2 thoughts on “GIT (SSH) with Visual Studio”

  1. Nice article.
    I am trying to use this setup on VS2015.

    After all the installations, in my TGIT menu, that is to the right of the Tools menu from VS2015, all the options are grayed-out. How to enable them?

    What should be the source control plug-in be set to under the Options menu? I only have 3 options: None/Git/Visual Studio Team Foundation Server. Is TGIT suppose to show up here as a source control plug-in or no?

    Thanks

    1. Hi,

      If all options are grayed-out it seems that you have no rights on VS. Did you try to open VS as administrator. Hold shift on icon and try with other user… Does it help?

      With news VS 2015 GIT source control is integrated into VS. you don’t even need to install TGIT on it. What version of VS do you use?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: