-
-
Save sangeeths/9467061 to your computer and use it in GitHub Desktop.
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 |
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.
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'.
I have an error that says fatal: refusing to merge unrelated histories. Any help would be appreciated !
@shrysr That probably happens because you already pushed something into the repo before you pulled from sync.
@gvillacisv I ran into the same message. --track
flag worked for me as well
In Bitbucket, go to Settings > Security > Connected Accounts. Link your GitHub account with Bitbucket and choose repos to import.
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.
Well explained how-to fork a github repo in a bitbucket server (initial status).
But what should i do, wenn the original repo changes? Should i merge the updated github-branch to master-branch and than push it?
What are the steps to:
- pull changes from forked repo
- merge it to my master branch
- push changes to my bitbucket-repo
@Ralcon: One possible way I can think off is; you maintain two branches in your destination (e.g. Bitbucket) repo. One branch which you wish to own (let's call it "master") and modify(maybe) and another which is replica of source (e.g. github.com) and let's call it "source". Now you need to keep updating your "source" and there shouldn't be any merge conflicts as every-time it is syncing to the latest or source. Later you can decide to merge "source" to "master" as and when you need.
--set-upstream
is no more supported use --track
instead
Use: git branch --track github sync/master
instead of git branch --set-upstream github sync/master
use git pull sync master --allow-unrelated-histories
Our local branch commit messages as it is only accepting certain format i.e []: message or else git push will fail,
as the upstream would have totally different commit message formats.
% git pull sync master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
If you run in to this, try connecting to the repo you want to fork with https instead of ssh. I hadn't set up keys on my system for git with ssh, so it complained.
If your main branch loses track of your origin (when it's not master
, e.g. main
), you can set it back with:
git branch --set-upstream-to=origin/main
Make sure that you were in the target branch, in the above example: main
.
https://bitbucket.org/repo/import