19

I have a gitlab Repository and I want it to update it on the bitbucket account.

Please provide me steps to follow, so that it can be helpful to me to migrate it in bitbucket from Gitlab.

Anubhav
  • 352
  • 3
  • 10
  • 22
  • 1
    What have you tried so far ? It's always possible to add an additional remote to a local clone and push to it. – marcolz May 22 '17 at 06:39

4 Answers4

43

1) Create the repository in Bitbucket using the UI

2) Clone the Gitlab repository using the "--bare" option

git clone --bare GITLAB-URL

3) Add the Bitbucket remote

cd REPO-NAME
git remote add bitbucket BITBUCKET-URL

4) Push all commits, branches and tags to Bitbucket

git push --all bitbucket
git push --tags bitbucket

5) Remove the temp repository

cd ..
rm -rf REPO-NAME
23

Follow these steps:

  1. Create a new repo in bitbucket.
  2. git clone <gitlabRepoUrl>
  3. cd <repoName>
  4. git remote add bitbucket <bitbucketRepoUrl>
  5. git push bitbucket master
Bishakh Ghosh
  • 1,205
  • 9
  • 17
  • Bishakh Ghosh : Thanks first. Do I have to commit each branch one by one? As when I did this only master is setup in the bitbucket. Please guide how to import all branches at once. – Anubhav May 22 '17 at 08:59
  • 10
    You can use `git push --all bitbucket` to push all branches. – Bishakh Ghosh May 22 '17 at 09:25
1

If you want to do it straight from the repositories themselves there is a way also.

  1. Rsync the /home/git/repositories directory (copying them is less risky than working on source files themselves) to your home dir

    sudo rsync -avzh /home/git/repositories /home/<YOURUSER>/repos/

  2. Set the permissions on your repos dir to yourself

    sudo chown -R <YOURUSER>:<YOURUSER> /home/<YOURUSER>/repos

  3. Create the empty repo on bitbucket.

  4. Mirror them locally to create a working copy that contains all branches and tags with you.

    git clone --mirror git@gitlab.mydomain.com/source-repo.git

  5. Then you would want to simply push the mirror.

    cd source-repo.git git push --mirror git@bitbucket.com/new-location.git

blamb
  • 4,220
  • 4
  • 32
  • 50
0

You must bear in mind that you must have a local copy of all remote branches and from that run

git push --all new-repository
git push --tags new-repository

Here is a try on how you can have local copies of all remote branches

#!/bin/sh
for i in $(git branch -r | grep -vE "HEAD|master"); do 
    git branch --track ${i#*/} $i; done
git push --all bitbucket
git push --tags bitbucket
Luis Rains
  • 11
  • 1
  • Hi! This is an answer to an old question, moreover it does not seem to address the topic... Could you explain why you wrote it? – Joël Oct 08 '21 at 13:29
  • because they have not indicated how to import the repository without losing the branches – Luis Rains Oct 13 '21 at 17:40