What is the best way to move a git repository with all branches and full history from bitbucket to github? Is there a script or a list of commands I have to use?
Here are the steps to move a private Git repository:
Step 1: Create Github repository
First, create a new private repository on Github.com. It’s important to keep the repository empty, e.g. don’t check option Initialize this repository with a README when creating the repository.
Step 2: Move existing content
Next, we need to fill the Github repository with the content from our Bitbucket repository:
$ git clone https://USER@bitbucket.org/USER/PROJECT.git
$ cd PROJECT
$ git remote add upstream https://github.com:USER/PROJECT.git
$ git push upstream master
$ git push --tags upstream
Step 3: Clean up old repository
Finally, we need to ensure that developers don’t get confused by having two repositories for the same project. Here is how to delete the Bitbucket repository:
Double-check that the Github repository has all content
Go to the web interface of the old Bitbucket repository
Select menu option Setting > Delete repository
Add the URL of the new Github repository as redirect URL
With that, the repository completely settled into its new home at Github. Let all the developers know!
In case you couldn't find "Import code" button on github, you can:
url
. It will look like: Public
or Private
repoBegin Import
UPDATE: Recently, Github announced the ability to "Import repositories with large files"
It's very simple.
Create a new empty repository in GitHub (without readme or license, you can add them later) and the following screen will show.
In the import code option, paste your Bitbucket repo's URL and voilà!!
Simplest way of doing it:
git remote rename origin repo_bitbucket
git remote add origin https://github.com/abc/repo.git
git push origin master
Once the push to GitHub is successful, delete the old remote by running:
git remote rm repo_bitbucket
I had the reverse use case of importing an existing repository from github to bitbucket.
Bitbucket offers an Import tool as well. The only necessary step is to add URL to repository.
It looks like:
In case you want to move your local git repository to another upstream you can also do this:
to get the current remote url:
git remote get-url origin
will show something like: https://bitbucket.com/git/myrepo
to set new remote repository:
git remote set-url origin git@github.com:folder/myrepo.git
now push contents of current (develop) branch:
git push --set-upstream origin develop
You now have a full copy of the branch in the new remote.
optionally return to original git-remote for this local folder:
git remote set-url origin https://bitbucket.com/git/myrepo
Gives the benefit you can now get your new git-repository from github in another folder so that you have two local folders both pointing to the different remotes, the previous (bitbucket) and the new one both available.