Setup a remote Repository using Git and Bitbucket

By:, On:

This tutorial assumes you have already completed:

In order to be able to leverage git and collaborate with other developers we will need to use "remote" git repository. Remote means that the repository will be saved on the server in the cloud (the internet). We do it because it will serve as a backup and it will make it easier for other developers to collaborate with us. The two most commonly used platforms are Github and Bitbucket. We will use Bitbucket because it allows us to create private repositories for free.

The process of setting up a remote repository for the first time is a little complicated but don't worry. Most of the work you only need to do once.

Step 1: Generate SSH Key

SSH key will be used by bitbucket to securely connect with you. We will also need it to deploy our application to the server. Good instruction for Mac and Linux can be found at this address: If you're on Windows:
We only need to do it once.

If you're on Mavericks, you can simply run one command and press "ENTER" until you're done (it will use default settings and no password for your key - it's still going to be secure if you don't share your computer)

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/lukasz/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/lukasz/.ssh/id_rsa.
Your public key has been saved in /Users/lukasz/.ssh/
The key fingerprint is:
90:00:0e:9d:d0:ae:b4:76:30:c8:e1:42:e2:e5:40:76 lukasz@lukaszs-air
The key's randomart image is:
+--[ RSA 2048]----+
|+*.E.            |
|o*=. . .         |
|B.*   o          |
|oB..   .         |
|o.+     S        |
|.o .             |
|. .              |
|                 |
|                 |

#now you can copy to clipboard.

$ pbcopy < ~/.ssh/

#it now sits in your clipboard so you can paste it wherever you want.  

Step 2: Register Bitbucket Account

Go to and create an account.

*Note: if you are in China, make sure to turn off your VPN when creating your account.

After you confirm your account head to the account settings.

Go to SSH Keys and add new key for the computer you're currently working on. If in doubt check the video above.

Step 3: Push to remote repository

All the steps above you only need to do once. Steps below you will do for every single application when you're getting started.

Let's create our first repository.

Once we give it a name click the option "I have an existing project to push up". It will give the instructions how to connect the remote repository and make the initial push.

If this is not your first run, make sure you initialize new git repository:

$ git init
$ git add . 
$ git commit -m "initial commit"

$ git remote add origin
$ git push -u origin --all

Now every time you want to synchronize your local and remote repositories you run the code:


$ git push

If you login you will be able to mark this tutorial as finished to track your progress


  • On: Guru wrote:

    Hi Lukasz, Thanks for your clear instructions and lessons. I have question: I already have a git and heroku account for which I have created the ssh key. Do I need to open a bitbucket account? If so, do I have to create a separate ssh key? Thanks Guru

  • On: Lukasz Muzyka wrote:

    Hi Guru,

    No. You don't need to generate new SSH if you already created one. You can copy this key to all services that use it for authentication (Bitbucket, Github, Heroku).

    Also, you can use either Bitbucket or Github for your code. They are almost identical in their nature. I use Bitbucket because it allows me private repositories for free.


You can login to comment