How to Migrate Git Repos from Bitbucket to GitLab



January 7, 2017

Migrate from Bitbucket to GitLab

There are a number of good Git service providers online, including GitHub (the most common) and BitBucket. Lately, however, I've been the most impressed with GitLab as a service provider. I think their interface is easier to understand than Bitbucket's and, unlike GitHub, offer free private repositories for individual users. In this post, I'm going to show you how to migrate a repository from BitBucket to gitlab.com.

Before You Get Started

Before you get started with this tutorial, you should create an account at gitlab.com. Before you being the migration process, it can also be helpful to login to your BitBucket account.

Create a New Project

To begin migrating a project from BitBucket to GitLab, click the "New Project" button found after clicking "Projects" in the main menu.

new GitLab project

Next, instead of giving the project a new name, click the BitBucket button under the header "Import project from". If you haven't already done so, you'll be asked to login to your BitBucket account. You also be asked to give GitLab (gitlab.com) access to your BitBucket account as part of a regular OAuth exchange. Click the "Grant Access" button to allow GitLab to receive data from your BitBucket account.

Choose Which Project(s) to Import

Once you've granted access to your BitBucket account, GitLab will display a list of projects from your BitBucket account that you can import. Any projects highlighted in green, as show in the screenshot below, are projects you've previously imported. To import all of your projects from BitBucket, simply click the "Import all projects" button at the top of the page. This will make exact copies of your BitBucket repos to your GitLab account. If you'd prefer to import a single project at a time, you can click the "Import" button the corresponds with each project.

import Bitbucket projects to GitLab

Change Your Project's Remote URL

Once you've created the new repo on GitLab, you'll need to point your local working directory to it's new remote locations. This can be accomplished using this Git command:

git remote set-url git@gitlab.com:gitlab-com/project-name.git

Make sure you use the URL assigned to your actual GitLab project. Once complete, you should be able to push and pull all you want on your new GitLab project(s).

Don't Forget Your to Update your SSH Keys

Before you'll be able to push to your new GitLab remote project, you'll need to add an SSH key to your GitLab account. This can be done under the "Profile Settings" menu found be clicking on your GitLab profile avatar. From there, select "SSH Keys" in the sub-menu and add your SSH key to your profile. If you are unfamiliar with this process, you can learn how to generate an SSH key for GitLab.

create SSH keys in GitLab

Finished

That's the easy import process you have with GitLab. Now go and enjoy using it instead of Bitbucket.