Forking from GitHub to Bitbucket

GitGithubBitbucket

Git Problem Overview


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’(?).

Git Solutions


Solution 1 - Git

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 [email protected]: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.

Solution 2 - Git

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://[email protected]/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).

Solution 3 - Git

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

Solution 4 - Git

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!

Solution 5 - Git

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:

  1. Click on the Create button and select Repository ('+' > Repository)
  2. Now, instead of creating a new repository select a import repository from the top right corner of the modal that pops up.
  3. fill in your github repo's URL and your authentication credentials on the new modal for importing the repository.
  4. That's it. Everything imports into bitbucket from github smoothly.

Note the import repository link on right top corner of the screenshot

Solution 6 - Git

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.

https://stackoverflow.com/questions/571232/svn-external-in-git

And later, even if you want to contribute to cakePHP, you can just do so at the original repo just fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionentropidView Question on Stackoverflow
Solution 1 - GitMartin GeislerView Answer on Stackoverflow
Solution 2 - GitaleembView Answer on Stackoverflow
Solution 3 - GitZubinView Answer on Stackoverflow
Solution 4 - GitshmuliView Answer on Stackoverflow
Solution 5 - Gitde1123bu58nkView Answer on Stackoverflow
Solution 6 - GitgcbView Answer on Stackoverflow