Migrating From Bitbucket to Github

Migrating repositories between bitbucket and github couldn’t be simpler thanks to the design nature of DVCS like git because the entire history is already located on your machine within your projects .git folder. All you’re really doing is changing a remote.

Open a terminal and navigate to your project directory.

TLDR;

For those who just want the commands with no explanation

1
2
3
4
git remote rename origin bitbucket
git remote add origin git@github.com:[username]/[repo_name].git
git push -u origin master
git remote rm bitbucket

Explanation of steps

Check which remote(s) you have now:

1
2
3
$ git remote -v show
origin    git@bitbucket.org:[username]/[repo_name].git (fetch)
origin    git@bitbucket.org:[username]/[repo_name].git (push)

Now rename your existing origin to bitbucket (or whatever you want to call it):

1
git remote rename origin bitbucket

Double check your change:

1
2
3
$ git remote -v show
bitbucket git@bitbucket.org:[username]/[repo_name].git (fetch)
bitbucket git@bitbucket.org:[username]/[repo_name].git (push)

Now add github as your origin and push the repository:

1
2
git remote add origin git@github.com:[username]/[repo_name].git
git push -u origin master

Check what remotes you have:

1
2
3
4
5
$ git remote -v show
bitbucket git@bitbucket.org:[username]/[repo_name].git (fetch)
bitbucket git@bitbucket.org:[username]/[repo_name].git (push)
origin    git@github.com:[username]/[repo_name].git (fetch)
origin    git@github.com:[username]/[repo_name].git (push)

Removed the old remote (bitbucket):

1
git remote rm bitbucket

Finally, check your remotes:

1
2
3
$ git remote -v show
origin    git@github.com:[username]/[repo_name].git (fetch)
origin    git@github.com:[username]/[repo_name].git (push)

Note that at the end of this, you still have your code on bitbucket, you’ve just pushed your repository to github and pointed your origin remote to there. To fully clean up you need to delete your repo from bitbucket.

git

Comments