Cloning a BitBucket Repo

ychinamale profile image Yamikani Chinamale ・2 min read


I have a repo called 'my-new-repo' on BitBucket. I'm going to walk you through the steps I took in order to clone that repo onto my machine.


First, set up an rsa key pair.

$ ssh-keygen
Generating public/private rsa key pair.

You have to assign a name to the key. You could choose to leave this section blank to give it the default name; it will also get saved in the default location. I chose to name mine 'wsl-default' and saved it in my current working directory.

Enter file in which to save the key (/home/yamikani/.ssh/id_rsa): wsl-default

For the purpose of this walkthrough, go ahead and leave the passphrase empty. The interaction should look something like this

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in wsl-default.
Your public key has been saved in wsl-default.pub.
The key fingerprint is:
SHA256:TosAyiMu6LNeibN4K+aGxwIXGzWgLsuL5peR+isxbc4 yamikani@LAPTOP-HBMDC5G1
The key's randomart image is:
+---[RSA 2048]----+
|  ..             |
| .  o            |
|. .. .           |
|o.o.             |
|++.+o   S        |
|B+==.. + .       |
|*BBoo . o        |
|OBOE             |
|X&B+.            |

List your directory to make sure the key files are there. If you

$ ls
wsl-default wsl-default.pub
# use 'ls ~/.ssh' if you used the default

Your public key file ends in '.pub', the other is your private key.

Next, start the ssh-agent and add your private key to it

$ eval `ssh-agent`
Agent pid 325

# adding private key to ssh-agent
$ ssh-add ./wsl-default
Identity added: ./wsl-default (./wsl-default)

Use cat to show the content of your public key. Copy the content and add a new ssh key to your BitBucket account.

To do this, click on your avatar at the bottom left of the BitBucket dashboard. Then click on 'Bitbucket settings' and then navigate to 'SSH Keys' under the 'Security' section. Go ahead and click 'Add Key'. Give your key a distinct label and paste the contents you copied into the 'Key' section. Hit save.

To confirm that you have correctly configured your Bitbucket for ssh, run the following command on the terminal:

$ ssh -T git@bitbucket.org
Warning: Permanently added the RSA host key for IP address '<ip_address>' to the list of known hosts.
logged in as yamikani

You can go ahead and clone our repository. To do this, open your repository's page in BitBucket and click on 'Clone'. Make sure the dialog reads 'SSH' at the top right corner before you copy the clone command. Copy and paste the command in your terminal and run it.

$ git clone git@bitbucket.org:yamikani/my-new-repo.git
Cloning into 'my-new-repo'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 12 (delta 1), reused 0 (delta 0)
Receiving objects: 100% (12/12), done.
Resolving deltas: 100% (1/1), done.

And there we have it.

Posted on by:

ychinamale profile

Yamikani Chinamale


Interested in eCommerce. I enjoy creating web and mobile apps. Fan of the React.js ecosystem. Unix for work, Windows for play.


Editor guide

If you wanna clone a bitbucket server (all repos on it), I've made a tool for that 😉