Forking a repository from GitHub to Bitbucket

There sometimes might be a need to create a private fork of a public project. With free account at GitHub this is not possible, but at Bitbucket it is.

In this example a public repository from GitHub is copied to Bitbucket as a private repository, with its remote addresses adjusted so that it can be updated by fetching from the GitHub repository and merged to the Bitbucket repository.

First choose the GitHub project from which the fork should be made.

I went ahead and took the first one that appeared on the trending list, which was at the time of writing icono.

Clone the repository locally and see the initial remote addresses:

git clone
cd icono
git remote -v

The last command from above should output something similar to:

origin (fetch)
origin (push)

The idea is only to use the fetch and assing it to a upstream alias:

git remote remove origin
git remote add upstream

More about the Git remote at the command specific documentation.

Now create a new repository at Bitbucket. Make sure to choose "private" and "Git" as the repository type. Then add the new origin remote address pointing to the new Bitbucket repository:

git remote add origin

Confirm with git remote -v that the remote addresses look like something similar to:

origin (fetch)
origin (push)
upstream (fetch)
upstream (push)

Once the addresses are ready, the initial push to Bitbucket can be started, but please note that depending on the size of the repository, it might take some time:

git push -u origin --all
git push --tags # pushes up any tags

More details about the switches used with git push at the given documentation. The second command is needed if the repository contains any tags.

The repository used as an example, icono was relatively small, only 123.3 KB thus pushed very quickly over to Bitbucket.

In case there are any problems with the access rights, it might be due to the SSH keys, specially in Windows. In order to see which keys are being used, run:

ssh -v

In order to pull any changes from the GitHub repository, use the commands below to merge them into the Bitbucket repository:

git fetch upstream master
git merge upstream/master
git push

Please note that while creating such a private fork of an open source project, any useful changes should be made available to the original project, as the people involved with it are in most cases working for free and out of passion for the code.