I'm working on a project based on CakePHP, that's hosted on GitHub. My project is being hosted on Bitbucket. Both of them use git. Basically I'd like to create a ‘fork’ (I don't know if I'm using the right terms, since I'm new to git) of CakePHP in my Bitbucket repository, in order to be able to get the updates without the need to download all the CakePHP zip/tar and replace the folder, then commit and push, but maybe with a ‘merge’(?).
-
5See http://stackoverflow.com/questions/1811730/how-do-you-work-with-a-git-repository-within-another-repository for a good approach to this kind of workflow. – Dolbz Nov 15 '11 at 14:40
6 Answers
It's not possible to send "pull request" across different sites today. I've added a feature request for this in the Bitbucket issue tracker: #3288. I suggest you add yourself as a follower if you want to track this.
However, you can still move the source from GitHub to Bitbucket without having to download any zip files or tarballs. You make a clone from GitHub and push to Bitbucket:
$ git clone https://github.com/cakephp/cakephp
$ cd cakephp
$ git push git@bitbucket.org:mg/cakephp.git master
I created mg/cakephp
as an empty Git repository in Bitbucket first. That way you can push/pull changesets from GitHub to Bitbucket.

- 312
- 3
- 12

- 72,968
- 25
- 171
- 229
-
3
-
1@RuchirShukla: the same way, basically. You have to move the commits through your own machine by pulling from your upstream. You then push that to the other hosting site, thereby synchronizing the two. – Martin Geisler Jul 17 '14 at 14:14
-
4This worked great for me except I needed to `cd cakephp` in-between the two commands. Obvious for non-beginners, yes, but beginners might wonder why it isn't working. – aaronbartell Feb 11 '15 at 22:05
-
Can you make a youtube video of this to demonstrate? I couldn't replicate it. I was able to do these instructions but when I push and commit, it still trying to push it to the master instead of the forked branch. – Wax Dec 25 '16 at 23:46
-
This does not work as a `fork`. Branches and Tags are NOT copied over to BitBucket. – Joel Karunungan Aug 23 '18 at 17:03
-
On a fresh repository without anything significant to override, you might want to add --force after master. like "git push https:// user-name@bitbucket.org/user-name/repo-name.git master --force". This could cause issues, but avoids being rejected on an initial commit. – Alexandre Jean Apr 22 '21 at 03:59
The workflow below adds the github repository as a a new remote called sync
and the bitbucket remote as origin
. It also adds a branch called github
to track the github repository and a branch called master
to track the bitbucket repository. It assumes you have a bitbucket repository called "myrepository" which is empty.
Setup remotes
# setup local repo
mkdir myrepository
cd myrepository
git init
# add bitbucket remote as "origin"
git remote add origin ssh://git@bitbucket.org/aleemb/myrepository.git
# add github remote as "sync"
git remote add sync https://github.com/aleemb/laravel.git
# verify remotes
git remote -v
# should show fetch/push for "origin" and "sync" remotes
Setup branches
# first pull from github using the "sync" remote
git pull sync
# setup local "github" branch to track "sync" remote's "master" branch
git branch --track github sync/master
# switch to the new branch
git checkout github
# create new master branched out of github branch
git checkout -b master
# push local "master" branch to "origin" remote (bitbucket)
git push -u origin master
Now you should have the local github
branch tracking the github repo's master
branch. And you should have the local master
branch tracking the bitbucket repo (master
branch by default).
This makes it easy to do a pull on the github
branch, then merge those changes onto the master
branch (rebase preferred over merge though) and then you can push the master
branch (will push it to bitbucket).
-
This doesn't seem to work but it's a good idea. Anyway to fix it to make it work? – bozdoz May 12 '13 at 00:27
-
Local github branch tracks remote github master branch, then you push to remote bitbucket master? When does the push to github occur? @aleemb – bozdoz May 12 '13 at 00:31
-
@aleemb, so, if I add repository on github like "sync", it will be "synced" like push to origin == push to sync? or I need to push to synced repository manually? – gaussblurinc May 27 '14 at 15:27
-
-
FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey) – Syaiful Nizam Yahya Jan 29 '15 at 07:31
-
This works great but is missing one step. you must first create the "github" branch to pull the "sync" remote to at the start of the "Setup Branches" Section. – Timee Mar 31 '15 at 05:06
-
1In Git 2.2.1 `--set-upstream` is deprecated...But this does work as long as you create the `github` branch before trying to set the upstream repo. – Ken Prince May 16 '15 at 19:06
-
4Instead of doing --set-upstream do: `git fetch` and `git branch --track github sync/master` – Beaudinn Greve Dec 16 '15 at 14:25
-
3I think what is missing is `git checkout github` and `git checkout -b master` after the git branch command. You will end up with those branches (`git branch -a`): github, master, remotes/origin/master, remotes/sync/master – Klemens Zleptnig Jun 08 '16 at 10:19
-
@aleemb your instructions work but Iḿ confused on how to do a git rebase afterwards with the github branch, care to explain a little more ? thanks!! – Juancho Jul 17 '18 at 23:17
-
Thanks for this guide, works like a charm, I did however chose "upstream" instead of "sync" as the github remote's name as it seems to be more in line with naming conventions. – Gregor Sondermeier Oct 27 '22 at 15:17
If you want to keep your repo up to date, use two remotes: Github (upstream
) and Bitbucket (origin
) like this:
# Clone original CakePHP source code from Github
git clone --mirror https://github.com/cakephp/cakephp
cd cakephp
# Rename remote from `origin` to `upstream`
git remote rename origin upstream
# Add your Bitbucket repo (this is where your code will be pushed)
git remote add origin https://bitbucket/your/repo.git
# Push everything to Bitbucket
git push --mirror origin
To pull updates to CakePHP from Github:
git pull upstream master
To push your code changes to Bitbucket:
git push origin master

- 9,422
- 7
- 48
- 52
-
I think you meant ` git clone https://mybitibucket/cakephp/cakephp` in the first `git` command, right? This is the way to go.... – ribamar Sep 15 '17 at 12:11
-
-
This also does not work. Branches and Tags are not included in Bitbucket. – Joel Karunungan Aug 23 '18 at 17:27
-
@JoelKarunungan Good point! To push everything, including branches and tags, I think this should work: `git push --all --mirror origin`. Answer updated. – Zubin Aug 24 '18 at 19:48
-
@Zubin did you try this? `fatal: --all and --mirror are incompatible` Also: `git pull upstream master` Throws a fatal error. `fatal: Couldn't find remote ref master` – Joel Karunungan Aug 25 '18 at 05:57
-
@JoelKarunungan Oops, sorry I didn't realise they couldn't be used together. It looks like it's better to use the `--mirror` tag with initial upstream clone and first push to Bitbucket. Answer updated. – Zubin Aug 26 '18 at 09:13
-
@Zubin question unrelated to this topic. If I fork a git repo to bitbucket this way, would I be able to add the ```cakephp``` as a submodule? – DavidKanes Sep 14 '22 at 16:44
When creating a new repository in BitBucket, click the button Import repository
at the top right. Enter the https url found when clicking Clone or download
in Github for the repository you want to fork.
Give your repository a name, configure your privacy settings, and there you go!
-
3
-
7The feature is labeled 'Import repository' on Bitbucket, as of now. – Wild Pottok Jun 20 '15 at 14:20
-
1@entropid a fork is a clone of the original repo. In the git world, Forking == cloning – enorl76 Jun 28 '16 at 21:10
-
2
-
4@enorl76 yes technically it is. But fork is a way to keep the clone "connected" to the original repository so to get update from it and eventually push on it. This is where the combination of 'origin' and 'upstream' links come to play a fundamental role. Github and Bitbucket then built all a set of tools around the upstream to make fork more productive and friendly, like the "push request" thing :) – Dan Niero Dec 04 '17 at 10:01
I have noticed that since @Martin Geisler 's answer, Bitbucket has enabled a feature to import repositories from github.com
I was able to successfully import a private repo from github.com into a private repo on bitbucket.org
Here are the steps:
- Click on the Create button and select Repository ('+' > Repository)
- Now, instead of creating a new repository select a import repository from the top right corner of the modal that pops up.
- fill in your github repo's URL and your authentication credentials on the new modal for importing the repository.
- That's it. Everything imports into bitbucket from github smoothly.
Note the import repository link on right top corner of the screenshot

- 49
- 2
I'm guessing you just want to easily download the repository with your project... and that you will NOT be contributing the cakePHP, correct?
if so, you just need to add a external reference to your repo.
SVN:externals equivalent in GIT?
And later, even if you want to contribute to cakePHP, you can just do so at the original repo just fine.