Instantly share code, notes, and snippets.

Embed
What would you like to do?
Forking a Github repo to Bitbucket
Go to Bitbucket and create a new repository (its better to have an empty repo)
git clone git@bitbucket.org:abc/myforkedrepo.git
cd myforkedrepo
Now add Github repo as a new remote in Bitbucket called "sync"
git remote add sync git@github.com:def/originalrepo.git
Verify what are the remotes currently being setup for "myforkedrepo". This following command should show "fetch" and "push" for two remotes i.e. "origin" and "sync"
git remote -v
Now do a pull from the "master" branch in the "sync" remote
git pull sync master
Setup a local branch called "github"track the "sync" remote's "master" branch
git branch --set-upstream github sync/master
Now push the local "master" branch to the "origin" remote in Bitbucket.
git push -u origin master
Courtesy: http://stackoverflow.com/questions/8137997/forking-from-github-to-bitbucket
@krisrandall

This comment has been minimized.

krisrandall commented Feb 1, 2017

To pull changes from the original :

git pull sync master
@binary10

This comment has been minimized.

binary10 commented May 13, 2017

In Bitbucket, go to Settings > Security > Connected Accounts. Link your GitHub account with Bitbucket and choose repos to import.

@flaketill

This comment has been minimized.

flaketill commented Oct 30, 2017

@daniele-niero

This comment has been minimized.

daniele-niero commented Dec 4, 2017

@binary10, @flaketill

Although the above is not a real forking (in the sense that it doesn't provide all the goods that forking gives, like push request) importing is a very different thing.
When you import you basically make a copy of the original repo and this copy is not connected to the original. It may also be a copy that uses a different versioning system (git to mercurial or vice-versa).
The recipe above is a way to make a copy still, but with a connection to the original repository, so that you can keep to stay up to date with it.

@gvillacisv

This comment has been minimized.

gvillacisv commented Feb 3, 2018

Well explained "how to", thank you.

Just adding a comment about new Git versions (currently I'm in v2.16.1). When I set up to track synced remote repository I got a fatal error:

$ git branch --set-upstream github sync/master
fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.

Then I used recommended option --track and it worked:

$ git branch --track github sync/master
Branch 'github' set up to track remote branch 'master' from 'sync'.
@shrysr

This comment has been minimized.

shrysr commented Mar 10, 2018

I have an error that says fatal: refusing to merge unrelated histories. Any help would be appreciated !

@adsc-cloudtec

This comment has been minimized.

adsc-cloudtec commented Apr 12, 2018

@shrysr That probably happens because you already pushed something into the repo before you pulled from sync.

@Lysak

This comment has been minimized.

@cnrmck

This comment has been minimized.

cnrmck commented Oct 23, 2018

@gvillacisv I ran into the same message. --track flag worked for me as well

@mohamedagamy

This comment has been minimized.

mohamedagamy commented Oct 25, 2018

In Bitbucket, go to Settings > Security > Connected Accounts. Link your GitHub account with Bitbucket and choose repos to import.

@jtcmedia

This comment has been minimized.

jtcmedia commented Dec 13, 2018

I have an error that says fatal: refusing to merge unrelated histories. Any help would be appreciated !

When you create the repository in Bitbucket, ensure you select No README or else it will create an initial commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment