Set up git with ssh keys on bitbucket

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. git@bitbucket.org: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 git@bitbucket.org:myproject/myproject.git (fetch) 
    origin git@bitbucket.org: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.

    $ ssh-keygen

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.

End.

Advertisements

Git remove all .pyc files

I ran into this recently with a project which already had several git commits but was still tracking .pyc files. This was starting to cause problems so I had to find a way to remove them from the repo:

    $ find . -name "*.pyc" -exec git rm -f {} \;

Then *.pyc can be added to the .gitignore file.

Thanks to Yuji Tomita for this information which can be found here.