9

I have to move a couple of repos from Gitlab to Bitbucket and discovered that the easiest way to do it seems to be:

  1. Create new empty repository in Bitbucket
  2. git clone --mirror git@gitlab.com:path/to/repo.git
  3. cd repo.git
  4. git remote set-url origin git@bitbucket.org:path/to/repo.git
  5. git push --mirror

This seems to copy the entire repo including tags, all branches etc. and I haven't discovered any disadvantages of this method yet. However, as I haven't seen this method anywhere on the internet, I'm afraid I'm missing something.

Can I safely use this method and remove the old repositories afterwards?

Rutger Bresjer
  • 411
  • 4
  • 13
  • I'm going to flag this as a possible duplicate of [What's the difference between git clone --mirror and git clone --bare](https://stackoverflow.com/questions/3959924/whats-the-difference-between-git-clone-mirror-and-git-clone-bare) simply because the accepted answer goes into _excruciating_ detail on how `--mirror` works. TL;DR I don't see any downsides, but it depends on your use-case. – msanford Mar 20 '18 at 15:05
  • 2
    I have seen that thread but it doesn't entirely answer my question. The thread answers the question what `--mirror` does, but not if there's any disadvantage of using it for moving repositories. (edit) Ah, your edit adds the missing info. Thanks! – Rutger Bresjer Mar 20 '18 at 15:07
  • 1
    Note that the `--mirror` clone and push will copy everything that *can* be copied through the Git interfaces. There are some things that *cannot* be copied: hooks (which you have to set via Bitbucket's web interface), reflogs (probably there are none on either side since bare repositories default to not having them), and other things you generally cannot touch through web interfaces at all, such as who (if anyone) has forked your repository on some hosting server. – torek Mar 20 '18 at 18:09
  • Is there some reason you aren't using https://bitbucket.org/repo/import ? – Jim Redmond Mar 20 '18 at 19:26
  • I cannot use the Bitbucket import because the Gitlab repo's are private and Bitbucket doesn't support the authentication methods Gitlab uses. – Rutger Bresjer Mar 26 '18 at 14:30
  • I also try to copy repo. Your way resulted in `fetch = +refs/*:refs/*, mirror = true` in config (AFAIK such repo won't work as expected). I guess you omitted some part of the procedure. Or maybe not and did something incorrectly. I've tried two way even: `path/to/repo.git` is new empty folder, it is same folder as in yours step (1). Or maybe it works specifically for bitbucket. TIA – Martian2020 Dec 12 '22 at 23:23

1 Answers1

0

From a repo-only standpoint, it should be safe. All refs (branches, tags) are copied as-is.

As torek mentioned in the comments, other things might be left out: configuration, hosting-specific settings, hooks.

knittl
  • 246,190
  • 53
  • 318
  • 364