Migrating a Github repo to Bitbucket (or similar services)

 TAGS:Github is awesome. Bitbucket is awesome too. They are both excellent services, but Bitbucket has a plus: it's free for private repos.

That's one of the reasons on why we decided to stop paying our $25/mo Github account for small projects and moved to Bitbucket. Although the Bitbucket guys have now a one-click "import from Github tool", the solution is so simple that I don't even think it is worth using it. Because at the end of the day, even if you uset it you'll need to change by hand where your origin points to anyway.

The following example is a Github to Bitbucket migration keeping the same files (no other clone needed). You can use this code for any service though, it works with any git repo:

First of all create your new blank repository and then go to your shell and do:

git pull
git push --mirror git@bitbucket.org:your_user/your_repo.git
git remote set-url origin git@bitbucket.org:your_user/your_repo.git
# or the same using HTTPS:
# git remote set-url origin https://bitbucket.org/your_user/your_repo.git

 These three lines do the following:

After this you can git pull/push/whatever as if nothing happened. You don't need to clone anything again. You have Github migrated to Bitbucket!