[Git] Adding your key to Bitbucket

When using our Bitbucket origin from a new computer, we will usually find this message:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

That’s normal. Bitbucket does not trust our computer yet, we have to add its key to the list of trusted hosts.

If you already have a SSH key, copy it and add it to bitbucket.

First, to copy it, open a terminal and write the following

cd ~/.ssh/
cat id_rsa.pub

Then you will find something like this*

ssh-rsa AAAB3NzaC1yc2EAAAADAQABAAABAQDGf57XkGtFONIn5fskaF1/6obxgLUq3r+lnyUkBJP6qIOyJ+0K[…]OdecdoOL8hQZagq+ff3X23GwfvJPj1Ytf your.mail@company.com

Copy this key in your clipboard, then log in into Bitbucket and do the following:

1.- Click on the user account icon (in the top-right of the screen)
2.- Then on “Bitbucket Settings”
3.- Now, under “Security”, click on “SSH Keys”
4.- Click on “Add key”
5.- Now assign a name to your key (e.g.: “My Laptop key”) and paste your clipboard inside the “Key” field. Click on “Add key”.

* If there is no id_rsa.pub or any .pub files, go to “Generating a new SSH key” section

Generating a new SSH key

In order to generate a new SSH key, write the following

ssh-keygen -t rsa -C “your_mail@company.com”

Generating public/private rsa key pair.

Enter file in which to save the key (/home/olmo/.ssh/id_rsa): mykey

Enter passphrase (empty for no passphrase): passphrase
Enter same passphrase again: passphrase

Your identification has been saved in mykey.
Your public key has been saved in mykey.pub.

Advertisements

[Git] Squashing commits

Taken from here https://ariejan.net/2011/07/05/git-squash-your-latests-commits-into-one/

Summing up:

git rebase -i HEAD~3

What we’re doing is rewriting the history to make 3 commits become a single one.
You can replace 3 by any number of commits to rewrite

pick f392171 Added new feature X
pick ba9dd9a Added new elements to page design
pick df71a27 Updated CSS for new elements

write the word “squash” in the ones that will be squashed

pick f392171 Added new feature X
squash ba9dd9a Added new elements to page design
squash df71a27 Updated CSS for new elements

Then Ctrl+X (if using nano on Linux)
Now another screen will appear, customize the commit message for all squashed commits and Ctrl+X again.