letsBeePolite
letsBeePolite

Reputation: 2251

Migrate from bitbucket to GitLab

I have multiple repositories in BitBucket. What is the most appropriate way to migrate from BitBucket to GitLab?

For an example, I maintain a repo on my system named "SSSP". What should be my steps to have a clean migration of that repository from BitBucket to GitLab?

Upvotes: 16

Views: 30935

Answers (6)

VonC
VonC

Reputation: 1329592

It is better to use an intermediate local bare repo in order to duplicate one remote repo and push it to a new remote one.

Assuming you have an empty gitlab repo ready:

git clone --bare [email protected]:old/old_repo.git
cd old_repo
git remote add new-origin [email protected]:new/new_repo.git
git push --mirror new-origin
cd ..
git clone [email protected]:new/new_repo.git repo
cd repo
# start working

Note that this won't include the wiki (which you need to clone as well if you have some content there), or the issues.


Note there is an import process more complete, and with GitLab 16.3 (August 2023), it includes:

Preserve pull request reviewers when importing from BitBucket Server

Until now, the BitBucket Server importer did not import pull request (PR) reviewers and instead categorized them as participants. Information on PR reviewers is important from an audit and compliance perspective.

In GitLab 16.3, we added support for correctly importing PR reviewers from BitBucket. In GitLab, they become merge request reviewers.

See Documentation and Issue.


More recently (2024), regarding BitBucket Cloud, GitLab 17.0 (May 2024) comes with:

Import from Bitbucket Cloud by using REST API

In this milestone, we added the ability to import Bitbucket Cloud projects by using the REST API.

This can be a better solution for importing a lot of projects than importing by using the UI.

See Documentation and Issue.

Upvotes: 17

Tobias Ernst
Tobias Ernst

Reputation: 4654

In case you use bitbucket-server and gitlab-ce.

First, open gitlab-ce admin interface, create a new group bitbucket-import. Afterwords create a new project within that group so that the folder /var/opt/gitlab/data/repositories/bitbucket-import should get created.

Then, copy the bare repositories from bitbucket-server data folder to gitlab-ce data folder:

cp -r /var/atlassian/application-data/stash/shared/data/repositories/* /var/opt/gitlab/data/repositories/bitbucket-import

Rename all folders from {folder} to {folder}.git. Gitlab-ce needs the .git ending to import the repository.

/var/opt/gitlab/data/repositories/bitbucket-import/
rename -n s/$/.git/ * # Dry run
rename s/$/.git/ * # Renaming

Import the repositories:

chown -R git:git /var/opt/gitlab/data/repositories/bitbucket-import/
gitlab-rake gitlab:import:repos['/var/opt/gitlab/data/repositories/'] RAILS_ENV=production

Now, you can see the imported git repositories in your gitlab admin interface represented through bitbucket id's. Here is how you can lookup the real name:

http://your-bitbucket-stash-server/rest/api/1.0/repos?limit=1000&start=0

Go to gitlab-ce project settings -> Advanced and rename your repositories.

Kind regards.

Upvotes: 1

ABHAY JOHRI
ABHAY JOHRI

Reputation: 2156

1.git -c http.sslVerify=false clone https://user@bitbkt:8443/scm/config.git

Will create clone from bitbucket on Local machine(Need proper rights for cloning the data from Bitbucket)

 2.cd  config

after cloning go into base folder

 3.git remote add sxm https://test.com/gitlab/xyz/config.git

Had created specific group on GitLab(xyz) and created config project in it.

4. git push sxm

Will push BitBucket code on GL Gitlab.

Upvotes: 0

Mikalai Daronin
Mikalai Daronin

Reputation: 8716

I suppose that using the import feature via web interface will be simpler than cloning and pushing each repo.

GitLab Documentation - Import your project from Bitbucket to GitLab

Also, Gitlab can import issues in that case.

Upvotes: 11

Haifeng Zhang
Haifeng Zhang

Reputation: 31925

I had this issue today and the links in the above answer out of date (404 Not Found). Finally I solved it and here's the steps how i made it and hope it helps for people who need it

Step1: Bitbucket

  1. login your bitbucket account

  2. got to Bitbucket settings

  3. select OAuth(on left side menu)
  4. select Add consumer
  5. fill in details:

    • Name
    • description
    • Callback URL
    • URL
  6. grant permissions

    • Account: Email, Read
    • Repositories: Read
    • Pull Requests: Read
    • Issues: Read
    • Wiki: Read and Write
  7. save your changes

Now the key and secret are generated like: enter image description here

Step2: GitLab

  1. open gitlab.rb file as root using vim(you can choose your preferable editor)

    sudo vim /et/gitlab/gitlab.rb

  2. initialize OmniAuth Configuration for initial settings: gitlab_rails['omniauth_enabled'] = true gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'twitter'] gitlab_rails['omniauth_auto_link_ldap_user'] = true gitlab_rails['omniauth_block_auto_created_users'] = true

  3. add Bitbucket provider configuration(key and secret we generated): gitlab_rails['omniauth_providers'] = [ { "name" => "bitbucket", "app_id" => "BITBUCKET_APP_KEY", "app_secret" => "BITBUCKET_APP_SECRET", "url" => "https://bitbucket.org/" } ]

  4. save the changes to gitlab.rb file

  5. run command gitlab-ctl stop, gitlab-ctl reconfigure and gitlab-ctl start to reconfigure the changes and restart gitlab.

Now you can see this confirmation modal: enter image description here

Upvotes: 7

TheWalkingPanda
TheWalkingPanda

Reputation: 183

I don't have 50 reputation so I can't comment but VonC is right. Spent about two hours trying to get GitLab's BitBucket import feature to work - I trashed it and simply added a new origin, re-pushed --mirror and deleted the older origin. When looking at the new GitLab server, I can see all the commits from the previous Git origin / server.

cd /dev-git-repo/
git remote add new-origin https://my-gitlab.my-gitlab-repo.com/myrepo-dev-git-repo
git push --mirror new-origin
git remote remove origin

Then you can test ...

echo "\r\nThis should be seen on GitLab not bitBucket" > README.md
git commit -m "updated readme.md"
git push new-origin

And you can see README was updated on gitlab and not on bitbucket.

Upvotes: 1

Related Questions