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:
- Visual Studio 2013 Pro
- TortoiseGIT version control
- Source Tree software
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:
- Download GIT from http://git-scm.com/
- Once downloaded run the installation
- Welcome screen (Figure 1).
- Accept license and terms conditions (Figure 2).
- Select installation destination folder (Figure 3).
- Select which context menu type you’d like to use. Select advanced to have all features (Figure 4).
- Choose create or not Start Menu Folder shortcut (Figure 5).
- 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).
- Select how GIT will manage files and folders checkout. Leave default recommended first option if not sure about implications (Figure 7).
- Wait to be installed (Figure 8).
- Welcome screen (Figure 1).
Click finish once installation is complete (Figure 9).
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:
- Go to “This PC”->”Properties” by mouse right clicking or “windows” + “break” key combination.
- 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).
- Select “Environment variable” to edit variable (Figure 11).
- In opened dialogue find “path” variable in “system variables” section. Click edit (Figure 12).
- 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).
- Restart of PC is required to make take it into account.
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
- Log in to your local computer as an administrator.
- In a command prompt, run: ssh-keygen -t rsa -C “label of the key” (Figure 14).
- Enter path where to save key. Note, that the last name specified is the name of the key and not the folder. (Figure 15).
- 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.
- 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.
Now you can exit command prompt.
You can download TortoiseGIT from https://www.google.be/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=tortoisegit.
- Download the latest version of TortoiseGIT source control. Select version of OS you are using x86 or x64.
- Install TortoiseGIT.
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:
- Go to TortoiseGIT installation BIN folder. Default is “C:\Program Files\TortoiseGit\bin\”.
- Open “puttygen.exe” (Figure 17).
- In opened window select “Conversions”->”Import Key” in menu bar (Figure 18).
- Select PRIVATE key generated previously by ssh-keygen (Figure 19).
- Enter passphrase specified while creating key (Figure 20).
- Enter “Key comment” as a key identification label (Figure 21).
- 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).
- Click “Save public key” to save public PPK key.
- Click “Save private key” to save private PPK key.
- You should now have four keys in your folder (Figure 23).
You can exit PuTTY Key Generator.
After source control is installed we can start to configure Visual Studio. This consists in installation of Visual Studio plugins for TortoiseGIT.
- Open Visual Studio IDE.
- In Menu select “TOOLS”->”Extensions and Updates”.
- Select “Online”->”Visual Studio Gallery” in the left pane.
- In search find in the top right corner type “TGIT” to find TortoiseGIT plugin.
- 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.
This plugin lets you easy create branches and releases. To download this plugin repeat steps from TGIT installation by finding “GitFlow” in search field.
To add private key to TortoiseGIT you should clone remote repository to your local system.
- Bring context menu of the TortoiseGIT in folder where you’d like to clone remote repository (Figure 24).
- Select “Clone” option.
- In opened window
- Set URL of remote repository.
- Set destination folder
- Check “Load Putty Key” checkbox to load private PPK key generated in previous steps.
- Browse for the key (Figure 25).
- Click OK to save.
- Enter passphrase of the private key.
Click OK when clone is finished.