Thursday, September 10, 2015

Using TortoiseGIT on Windows, with BitBucket

A very common requirement for a developer is to host code on BitBucket, and then use it for version control on his Windows machine. The GIT client chosen, usually is TortoiseGIT.

It turns out, that there are more than a few steps required to get this working correctly and I could not find a good first search result to get it working. I had to jump across various articles before I could stitch my process together. Here I have consolidated the steps in the hope that it would help other too.

This tutorial might also fix some errors which you might be getting such as the dreaded permission denied (publickey) or Permission Denied errors while committing. 
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

git did not exit cleanly (exit code 128)

I am writing this on Windows 8, but this would apply to Windows 7 too.

  1. Begin by installing Putty on your Windows machine. Remember to install the complete installer, provided under the heading "Windows installer for everything except PuTTYtel". You can get it from here
  2. This will usually install the tool at c:\Program Files (x86)\PuTTY if you have proceeded with default settings.
  3. Next, run PuTTYgen to generate the Private ad Public SSH keys which we will require for this process. Select "SSH-2 RSA", and hit 'Generate'. Move the mouse in the blank area to generate the required keys.
  4. Once the tool has generated the keys, preferably provide a 'Key passphrase'. This is just a password to better protect your private key. Now use the buttons provided to save the Private and Public keys in some safe folder for future reference. Leave the PuTTYgen window open for now as we will need it a bit later again.
  5. Now run Pageant from Windows. Click on 'Add Keys', and provide it the private key file you had saved in the above step. Hit 'Close'
  6. Now from the already open PuTTYgen window, copy the text inside the box titled "Public key for pasting into Open SSH authorized_key file”"

  7. Now, we need to tell BitBucket about these new keys too. So open your BitBucket account and click 'Manage Account' 
  8. Click on 'SSH Keys' on the left hand menu. Click on the 'Add Key'. Here, paste the key which you copied from the step 6. above. Click on 'Add Key' to save the key.
  9. Finally, when we install TortoiseGIT, then by default it uses ssh.exe. Change it to use plink.exe. For this, in the folder on your computer which has the repository, right click and open TortoiseGIT settings. Under 'Network', provide the path to your plink file, which got installed when you had installed Putty.
  10. While you are in the setting, also check that under 'Git' > 'Remote', click on 'origin', and then the url provided is the one you got from BitBucket. Note that from Bitbucket you need to get the SSH url and not the HTTPS url. I also provided my private key on this page, but not really sure if that is mandatory.

*Phew!* That's quite a long list of steps to get this working, but once done, hopefully your TortoiseGIT will work super smoothly, not asking for authentication every now and then, and pushing your commits as intended.

Do leave a comment if this helped you too!


sunitha vishnu said...

This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
Android Training in Chennai
Ios Training in Chennai

isabellaJoseph said...

hi admin.i am really love it your blog.Because your explanation wise all the topics are too good.Thanks for sharing.. Devops Training in Bangalore
Software Testing Training in Bangalore