Categories
Featured Articles Git

Setting up Git and TortoiseGit with Bitbucket, step by step (2024)

[Edit: I finally updated the post with the latest changes. Thank you for everyone who kept returning to this post (and left comments too) from 2012!]

I wanted a set of instructions for my colleagues and friends when they want to setup Git and TortoiseGit on Windows (connected to Bitbucket). There are some steps that I have to Google myself too every time, because I don’t install Git & TortoiseGit everyday.

Okay, so this post is going to be a bare-bones, step by step guide for me or anyone (No backgrounds, theories and other noise)

Basics:

  • Git – is a free and open source distributed version control system.
  • TortoiseGit – is a Git client (GUI interface).
  • Bitbucket – is a web-based project hosting service (supports Git and Mercurial)

Assumptions:

  • You already have a Bitbucket account. If not, you can create one here.
  • I’m installing this on Windows 11 – 64bit. I assume you can adapt to minor differences in your flavor of Windows.

Installing Git

1. Download the latest Git for Windows → http://git-scm.com/download/win

2. Start the installation and continue clicking “Next” until you come to the “Select Components” view (see below).

Make sure “Open Git Bash here” is checked, as shown in the image (This will add an entry in the right-click context menu of folders). I unchecked “Open Git GUI here”, because I don’t use it. Everything else is default. →

Select Components view – Git installation

3. Continue clicking “Next” and finally click “Finish” to complete the setup. We have completed installing Git. (Note: Feel free to change any setting if you know what you’re doing. I didn’t change anything though)

Configure Git settings

1. Click Start Menu and type “Git Bash” and press Enter to open a Git command-line window

2. Provide your name and email address to Git, so that it will label your commits properly.

For example, if you want your name to look like “John Doe” in your commits and your email address (registered with Bitbucket) is johndoe@doebrothers.com, you would enter the following two commands (press Enter after each line) →

git config --global user.name "John Doe"
git config --global user.email "johndoe@doebrothers.com"

This is how it would look in Git Bash for me →

Commands to configure name and email in Git config

Create SSH identity and copy public key to clipboard.

To make sure we don’t enter our username and password every time we push to or pull from the Bitbucket repository, we will use SSH (secure shell) to communicate with Bitbucket (there are other methods, but for this post we will stick to SSH). Lets go ahead and create our SSH identity to communicate with Bitbucket.

1. Click Start Menu and type “Git Bash” and press Enter to open the Git command line (if it is not already open)

2. Type the following command and press Enter →

ssh-keygen –t rsa –C "johndoe@doebrothers.com"

(Use your email address registered with Bitbucket)

You will be prompted to provide file location and to enter a passphrase twice. Keep pressing the Enter key to accept the default file locations and to skip providing a passphrase.

Now the key files are generated. Easiest way to copy the contents of the public key to the clipboard is to use the “clip” command as follows →

clip < ~/.ssh/id_rsa.pub

Once you press Enter, the contents will be in clipboard, ready to be pasted.

This is how it will look in Git Bash →

Create SSH identity and copy to clipboard

Add the copied public key to Bitbucket

1. Log into Bitbucket, click on the “settings” cog wheel and then select “Personal Bitbucket settings”

Select Personal Bitbucket settings

2. Click on the “SSH keys” link under “Security” section of the settings and click on “Add Key” button on the right, to add a new key.

Add SSH key in Bitbucket

3. In the “Add SSH key” popup that comes up, paste the copied contents of the public key in the “Key” text box.

4. Provide a label for this key in the “Label” text box, to identify it (optional). For example it could be “Personal Laptop”.

5. Click on the “Add key” button to save and close the popup. Key with the “Personal Laptop” label (or any other name provided) should be listed like in the following image →

Added public key in bitbucket

At this point we have everything ready to work with Git and Bitbucket… ONLY if you are someone who loves the command-line! Winking smile

If you were one of those rare breeds, you wouldn’t even be here reading this guide. So let’s continue and see how we can install and setup TortoiseGit as our GUI interface for Git (there are many other excellent Git clients too, that you can try, e.g.: SourceTree)

 

Installing TortoiseGit

1. Download the latest TortoiseGit here → https://tortoisegit.org/download/ (Make sure you select the right setup for your PC – 32bit or 64bit).

2. Start the installation. On the last screen it will present you the option to start the “Run first start wizard”. Remember we have already set name and email address in Git config? We don’t have anything to change because of that. But I still ran the wizard, and finished it.

TortoiseGit Run first start wizard

3. Once you click “Finish” here or in the wizard, we are done with the setup.

 

Let’s test our installation

We need a valid Git repository in Bitbucket to test our installations and configurations.

Go to an existing repository in Bitbucket or create a new repository (this can even be a repository to only test Git with Bitbucket, that you can delete immediately).

1. Click on the “Clone” button on top.

2. Select “SSH” from the drop-down.

3. You will see a text box with all its text selected. “git clone” is a command and we don’t need that now. So, copy everything else.

This is how it would look in Bitbucket →

Copy repository link to use with SSH

If you paste the copied text to a text editor like Notepad, it should look something like the following (Note that there’s no “git clone” command in it. If you accidentally copied that too, copy again WITHOUT it).

git@bitbucket.org:guganeshan_t/sample-repository.git

Some parts will be different for you because you will have a different username and repository name. This is our clone URL.

4. Let’s “clone” the repository on the desktop (you can delete and try a different location later). Right-click on the Desktop and select “Git Clone…” from the context menu.

5. A window will popup. Paste the copied clone URL in the “URL” box and click Ok →

Clone repository window in TortoiseGit

6. If this is the 1st ever time you are communicating with Bitbucket using SSH, you will see the following message (Git doesn’t know Bitbucket as a host yet) →

Bitbucket as a host, first time

Just click “Yes” to remember bitbucket.org in future sessions.

Now, if you got the above confirmation dialog because it’s the 1st time communicating with Bitbucket, TortoiseGit most probably will show you a “fatal” error message (happened to me). This is fine. Click “Retry” and now it should clone your repository successfully →

Cloned successfully from Bitbucket

 

Commit a new file to your repository and Push to Bitbucket

Only when you could commit and push a file to Bitbucket without a problem, that we can confidently say our setup works.

Yeah, that’s “home-work” for you and I’m not going to list any steps here Winking smile

Since the purpose of this article was to setup the necessary tools, “how to” work with these tools is beyond scope (Can be discussed in another article maybe).

 

EXTRA STEP, only if it still fails for you

There could be SSH related problems if you had previous installations that used other SSH clients. I have not used anything else here, so I am unable to help, but here’s how you verify if it uses “ssh.exe” in TortoiseGit settings after the installation is complete  →

  1. Right-click on any folder and select: TortoiseGit → Settings, from the context menu.
  2. Click on the “Network” node.
  3. You will see the “SSH client:” option on the right.
  4. Make sure it has only ssh.exe in it.
  5. Click Ok.

Here’s a screenshot of the Network options in TortoiseGit settings →

SSH client in TortoiseGit settings

 

Your feedback!

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, so that I can make sure its simple for everyone.

Adiós

108 replies on “Setting up Git and TortoiseGit with Bitbucket, step by step (2024)”

Thank you very much!
Easy instruction. Bitbucket changed its interface again but otherwise quite easy to follow the steps.

This is fantastic. Applies to Visual Studio online repos as well. I was using SourceTree and kept getting prompted to enter my VS credentials every time I did a push/pull/commit. I uninstalled and wanted to use TortoiseGIT (I know TortoiseSVN pretty well so wanted to keep this similar). For VS, just use the same steps to add SSH key to VS online repo.

I followed the instructions provided, but i ran into an error towards the “Let’s test our installation” part. When I went to clone the repository onto my desktop, I ran into an error that said “no supported authentication methods available”. Would you happen to know why that is the case?

Hi Edward, sorry for the delay. Hope you found a solution (Please let me know if you haven’t)

It’s been almost a decade since I wrote this post and there are some changes to the installation & setup now. I’m hoping to update the post with latest changes.

@Edward
You can skip the SSH key part. Delete the added key from Bitbucket and try gitclone using tortoise git.
The credentials will be asked at this stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.