Skip to content

Instantly share code, notes, and snippets.

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
cd myforkedrepo
Now add Github repo as a new remote in Bitbucket called "sync"
git remote add sync
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
Copy link

adilsammar commented Aug 16, 2019

--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

Copy link

abhaynpai commented Apr 25, 2020

use git pull sync master --allow-unrelated-histories

Copy link

scheung38 commented Feb 19, 2021

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.

Copy link

pavelkomarov commented Jan 28, 2022

% git pull sync master 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.

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