Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save svanas/87330eeb17313ea50d5cf9c265ab693f to your computer and use it in GitHub Desktop.
Save svanas/87330eeb17313ea50d5cf9c265ab693f to your computer and use it in GitHub Desktop.
TortoiseGit for Bitbucket and GitHub for Windows

Setting up TortoiseGit for Bitbucket and GitHub for Windows, on the same PC, step by step.

This is an addendum to Guganeshan Thambiraja's excellent writeup on how to set up Git and TortoiseGit with Bitbucket, step by step.

Posted by Stefan van As on May 12, 2016. Added Yubikey steps on July 13, 2016.

What if...

  1. You want to use TortoiseGit with Bitbucket, and
  2. You already have GitHub for Windows, or
  3. You want to use GitHub-for-Windows-with-GitHub, and TortoiseGit-with-Bitbucket.

These instructions with help you set that up, step by step.

  1. Install GitHub for Windows
  2. Create SSH identity for Bitbucket
  3. Add your public key to Bitbucket
  4. Create a SSH config file
  5. Install TortoiseGit
  6. Clone a Bitbucket repo
  7. Add your Yubikey to Bitbucket (optional bonus step)

Wait, why would I want to do that?

GitHub for Windows is by far the easiest GitHub client on Windows. It is super easy to setup because portable git.exe is included -- no need to download and install that separately. Also, it will not ask you for your password every time you interact with GitHub.

Unfortunately, GitHub does not offer private repositories with their free plan. This is where Bitbucket comes in. With Bitbucket, you get unlimited private repositories, and they are free for small teams of 5.

While I'm sure SourceTree (the recommended client for Bitbucket) is great, I found it less user-friendly than GitHub for Windows. Also, I had a hard time getting GitHub for Windows and SourceTree play nice with each other. SourceTree kept telling me how "the procedure entry point could not be located". I'm guessing Git-included-with-GitHub-for-Windows was fighting with Git-included-with-SourceTree. Oh well.

I wish I could use the GitHub client both for GitHub and Bitbucket, but the GitHub client connects to one remote and one remote only. I started searching for a Bitbucket client that would play nice with GitHub for Windows, because I want the latter to stay. TortoiseGit to the rescue.

Prerequisites

  1. You already have a GitHub account
  2. You already have a Bitbucket account

Step 1: Install GitHub for Windows

  1. Download GitHub for Windows
  2. Log into GitHub for Windows, using your GitHub account.
    Log into GitHub for Windows
  3. Configure Git. Note: Git will label your commits with this info (including your Bitbucket commits).
    Configure Git
  4. There is no step 4. GitHub for Windows will automagically add a new public SSH key to your account. Honestly, they have the easiest setup.

Step 2: Create SSH identity for Bitbucket

To make sure we don’t have to enter our username and password every time we push to or pull from the Bitbucket repository, we should use SSH (secure shell) to communicate with Bitbucket. Lets go ahead and create our SSH identity to communicate with Bitbucket.

  1. Launch GitHub for Windows. Click on the gear icon (in the upper-right corner), then click on Options. Under Default shell, change that from PowerShell to Git Bash.
    Default shell
  2. Double-click on the shortcut named Git Shell that you see on your Windows desktop.
  3. Type the following command and press Enter →
    ssh-keygen -t rsa -C "johndoe@doebrothers.com"
    (use your email address registered with Bitbucket)
  4. You will be prompted to provide a file name. Type the following and press Enter →
    /c/Users/<your user name>/.ssh/bitbucket_rsa
    (use your Windows user name)
  5. You will be prompted to provide a passphrase. Press Enter →
  6. Copy the contents of your newly created public key to the clipboard:
    clip < ~/.ssh/bitbucket_rsa.pub

Step 3: Add your public key to Bitbucket

  1. Log into Bitbucket and click on your avatar (in the upper-right corner), then click on Bitbucket settings.
  2. Click on SSH keys in de side bar, then click the button labelled Add key.
  3. In the Add SSH key popup that comes up, paste your public key in the text box labelled Key.
  4. Click on the button labelled Add key to save and close the popup.

Step 4. Create a SSH config file

  1. Using your favorite text editor, create a new file here or edit the file if it already exists:
    c:\Users\<your user name>\.ssh\config

  2. Add an entry to the configuration file for GitHub using the following format. Note: the second line is indented. That single space is important, so make sure you include it.

    Host github.com
     IdentityFile ~/.ssh/github_rsa
    
  3. Add an entry to the configuration file for Bitbucket using the following format. Note: the second line is indented. That single space is important, so make sure you include it.

    Host bitbucket.org
     IdentityFile ~/.ssh/bitbucket_rsa
    
  4. Save and close the file.

Step 5. Install TortoiseGit

  1. Download TortoiseGit. If you are running a 64 bit system, you do not need to download the 32 bit version.
  2. Start the installation and keep clicking Next until you come to the following step. Choose OpenSSH, Git default SSH Client here.
  3. Keep clicking Next until you have completed the setup.
  4. Right-click on your desktop and select TortoiseGit > Settings from the context menu. You should see the following screen. Click on: Set Git path.
  5. Paste this in the text box labelled Git.exe Path:
    C:\Users\<your user name>\AppData\Local\GitHub\PORTAB~1\cmd
    (use your Windows user name)
  6. Click on the button labelled Check now (optional).
  7. Click on OK.
  8. Right-click on your desktop and select TortoiseGit > Settings from the context menu.
  9. Click on Network in de side bar.
  10. Paste this in the text box labelled SSH client:
    C:\Users\<your user name>\AppData\Local\GitHub\PORTAB~1\usr\bin\ssh.exe
    (use your Windows user name)
  11. Click on OK.

Step 6. Clone a Bitbucket repo

  1. Log into bitbucket.org
  2. Go to an existing repository or create a new repository.
  3. Click on Clone in the side bar.
  4. Select SSH from the drop-down.
  5. You will see a text box to the right with all its text selected. git clone is a command and we don’t need that now. So, copy everything else.
  6. If you paste the copied text to your favorite text editor, it should look something like the following:
    git@bitbucket.org:svanas/sample-repository.git
    This is our clone URL. Note that there’s no git clone command in it. If you accidentally included that, copy again WITHOUT it. Some parts will be different for you because you will have a different username and repository name.
  7. Right-click on your desktop and select Git Clone… from the context menu.
  8. The following window will appear. Paste the copied clone URL in the text box labelled URL and then click on OK.
  9. If everything went fine, you should see a blue success message at the bottom in TortoiseGit once the cloning is complete.

Step 7. Add your Yubikey to Bitbucket (optional bonus step)

You can strengthen your Bitbucket password by adding a Yubikey to your account. The Yubikey is a small hardware device that offers two-factor authentication with a simple touch of a button.

Yubikeys are awesome and I highly recommend them because they are simple devices that really improve your online security. Combining your Bitbucket password ("something you know") with your Yubikey ("something you have") strengthens the security of your Bitbucket repos.

Your Yubikey needs to support FIDO U2F. Luckily all modern Yubikeys do -- including the $18 Yubikey.

First, you will need to enable two-step verification:

  1. Log into your Bitbucket account
  2. Click on Two-step verification in the side bar.
  3. Enter your Bitbucket password, then click on Set up two-step verification.
  4. Download a two-step verification app for your phone. I recommend Google Authenticator.
  5. Launch Google Authenticator on your phone, then scan the QR code on the Bitbucket web site with it.
  6. Enter the verification code from Google Authenticator into the Bitbucket website, then click on Enable two-step verification.

Now that you have enabled two-step verification, it is time to add your Yubikey:

  1. Log into your Bitbucket account
  2. Click on Two-step verification in the side bar.
  3. Under Device name enter Yubikey (or any other name you want to call your Yubikey device).
  4. Click on Add security key.
  5. Insert and press the button on your Yubikey now.
  6. There is no step 6. YubiKeys do not require any additional overhead (such as drivers or client-side software).

I want to keep this post as simple as possible for anybody to follow. If you found any areas where it is not clear, please let me know below in the comments. Thanks!

--Stefan van As, May 2016.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment