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 https://github.com/saeedalipoor/icono.git cd icono git remote -v
The last command from above should output something similar to:
origin https://github.com/saeedalipoor/icono.git (fetch) origin https://github.com/saeedalipoor/icono.git (push)
The idea is only to use the
fetch and assing it to a
git remote remove origin git remote add upstream https://github.com/saeedalipoor/icono.git
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 email@example.com:paazmaya/icono.git
git remote -v that the remote addresses look like something similar to:
origin firstname.lastname@example.org:paazmaya/icono.git (fetch) origin email@example.com:paazmaya/icono.git (push) upstream https://github.com/saeedalipoor/icono.git (fetch) upstream https://github.com/saeedalipoor/icono.git (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 firstname.lastname@example.org -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.