Migrate repo from Gitlab to Github

本文转自https://gist.github.com/mariozig/bd3bb50593e6d911946b

# Assume we are in your home directory
cd ~/

# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git

# Change into newly created repo directory
$ cd ~/my-repo.git

# Push to GitHub using the `--mirror` option.  The `--no-verify` option skips any hooks. 
$ git push --no-verify --mirror git@github.com:mario/my-repo.git

# Set push URL to the mirror location
$ git remote set-url --push origin git@github.com:mario/my-repo.git

# To periodically update the repo on GitHub with what you have in GitLab
git fetch -p origin
git push --no-verify --mirror

when migration has big file issue:

1). Clone with –mirror from Gitlab

git clone --mirror https://your-gitlab-site.com/mario/my-repo.git

2). Use BFG to clear tree and reduce repo size

java -jar bfg-1.13.0.jar --strip-blobs-bigger-than 50M my-repo.git
git reflog expire --expire=now --all && git gc --prune=now –-aggressive

3). Push to github with --mirror

git push --mirror --no-verify https://github.com/mario/my-repo.git > push.log 2>&1

 这样会有一个问题,这种情况bfg会保护当前版本(HEAD所指的版本),不去清理。提示如下:

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit ******* (protected by 'HEAD')

 解决方法:

java -jar bfg-1.13.0.jar --strip-blobs-bigger-than 50M my-repo.git --no-blob-protection

 

HTTPS://gist.GitHub.com/Mario资格/百度3宝宝50593哦6的911946不
[HTTPS://Gist.GitHub.Com/Mario zīgé/bǎidù 3 bǎobǎo 50593 ó 6 de 911946 bù]
HTTPS://gist.GitHub.com/Mario qualifications / Baidu 3 oh baby 50 593 9119466 does not
posted @ 2020-03-17 17:59  始怡  阅读(287)  评论(0编辑  收藏  举报