Migrating a repository from Bitbucket to GitHub

Migrating a repository from Bitbucket to GitHub

Several years ago, we started using Bitbucket because it provided unlimited private repositories. But today, GitHub also offers the same plus useful tools and integrations. So, we started to migrate repositories from Bitbucket to Github.

Let's start by looking at the commit history (master branch) of the repository we want to migrate. Run git log --oneline --graph:

*   2849da4 (HEAD -> master, tag: 1.0.0, origin/master, origin/HEAD) Pull request #2: Update README.md
|\
| * f5ec292 (origin/release/1.0.0, release/1.0.0) Update README.md
|/
* ce82b26 Create README.md

And the remote branches with git branch -r:

  origin/HEAD -> origin/master
  origin/develop
  origin/master
  origin/release/1.0.0

The idea is to move everything to the new repository using the minimum number of git commands.

Step 1: Create

Create a new repository on GitHub. The repository needs to be empty, with no README file, no license file, and no .gitignore file:

Step 2: Clone

Run git clone --bare https://raulnq@bitbucket.org/raulnq/old-repository.git:

Cloning into bare repository 'old-repository.git'...
remote: Enumerating objects: 8, done.
Receiving objects: 100% (8/8), done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
Resolving deltas: 100% (1/1), done.

Step 3: Push

Run cd old-repository.git and git push --mirror https://github.com/raulnq/new-repository.git:

Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 20 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (8/8), 834 bytes | 834.00 KiB/s, done.
Total 8 (delta 1), reused 8 (delta 1), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/raulnq/new-repository.git
 * [new branch]      develop -> develop
 * [new branch]      master -> master
 * [new branch]      release/1.0.0 -> release/1.0.0
 * [new tag]         1.0.0 -> 1.0.0

Step 4: Check

And that's it. You can clone your new repository and start to work on it. Thank you, and happy coding.