I found the bitbucket documentation on this a little verbose.
So here is my minimalist guide. I assume that there is already a repo created in bitbucket.
1. Copy the ssh url from bitbucket. On your repo page there should be a section along the lines of Clone this repository.
Hit SSH and copy the url part (e.g. email@example.com:myproject/myproject.git).
2. On the local machine:
$ git remote set-url bitbucket
3. Check the remote address:
$ git remote -v
This should show something like:
origin firstname.lastname@example.org:myproject/myproject.git (fetch) origin email@example.com:myproject/myproject.git (push)
4. Now let’s generate a new SSH key. If you already have an SSH key for the machine, then that can be used. These instructions assume this is the first. Go ahead an accept the default location for saving and if you don’t want to be asked for a password each time you push/pull (which is one of the big advantages of using ssh keys), then hit Enter for the passphrase.
5. Go to the public part of the saved key. It’s probably in
/home/.ssh/id_rsa.pub. Copy it.
6. Now, on the bitbucket site, go to user->account->ssh keys, and paste the key into the box. Label the key something logical.
7. Back on the local machine:
$ git push origin master
This should push your repo as normal, but using the SSH protocol and without the need for a password.