I haven’t updated this blog in a while and it took me a while to find the repository. And to my shock it was still in bitbucket, I haven’t been there in ages! Surely most of us have already moved our private and personal git repos over to github now that it’s free to host private repositories there. It’s just so much nicer place in my opinion.

Well, to make it more enjoyable to update this blog in the future, I decided to move the repository to github. Plan of action was to clone the repo from bitbucket, change the origin to my newly created github repo and push.

Well, it wasn’t that easy.

I directly copied from bitbucket web interface the following two git clone commands (SSH and HTTPS) and both of them failed with authentication failed error.

% git clone https://myusername@bitbucket.org/myusername/myblogrepo.git
Cloning into 'myblogrepo'...
Password for 'https://myusername@bitbucket.org': 
remote: Invalid username or password
fatal: Authentication failed for 'https://bitbucket.org/myusername/myblogrepo.git/'

% git clone git@bitbucket.org:myusername/myblogrepo.git
Cloning into 'myblogrepo'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

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

This is likely caused by an old password in your git credentials manager. How to update it? Depends what OS you’re on, I followed many articles and forum posts similar to this:

https://seankilleen.com/2021/01/how-to-force-git-to-prompt-you-for-a-password/

I didn’t like this approach, seems wrong, but I kinda tried it…

The wrong and hard way (aka. “DON’T DO THIS”)

I tried getting, erasing the old credentials and storing the new credentials with following commands (I don’t recommend it so please skip to the “EASY WAY” section if you just want the answer):

% git credential-osxkeychain get
% git credential-osxkeychain erase
% git credential-osxkeychain store

It was all super complicated and interesting exercise to get to know this obscure “credentials-osxkeychain” git command, and I don’t really understand why did I go to these lengths only to fail.

Using the SSH key (aka the “EASY WAY”)

So this is the approach that worked the easiest.

Go to bitbucket personal settings at https://bitbucket.org/account/settings/, click SSH keys on the left side menu and arrive probably something like https://bitbucket.org/account/settings/ssh-keys/

Click “add key”.

Give it a name, anything you think is descriptive, then use the following command in your terminal to get your machine’s SSH public key onto your clipboard (If you don’t already have a public key on that machine, you can easily generate one by using ssh-keygen -o command):

cat ~/.ssh/id_rsa.pub | pbcopy .

Now just paste the value back to bitbucket web interface where it says “key”, then click the “add key” button.

After these steps you should be able to clone the repository using the SSH protocol, just copy the command from the bitbucket web interface behind your repository’s clone button, it should look something like this:

git clone git@bitbucket.org:myusername/myrepo.git

Worked like a charm, no username or password prompts and now I had the repository to push it to it’s new home. Goodbye bitbucket!