gitee迁移到gitlab

gitee迁移到gitlab

gitee上repo批量pull

好些仓库在gitee上,想都 pull下来慢慢看。

参考这个:https://www.cnblogs.com/Soar1991/p/15356513.html

可以从网页上获取到当前页所有仓库链接。手动翻几页,重复操作一下,就获取到所有的仓库地址了

然后放到脚本里。 notepad++编辑器打开,列块编辑,前面添加 git clone --bare 也可以不加--base选项

gitee上的库批量转存到自己的gitlab私库

参考gitlab这这几个文档: https://docs.gitlab.cn/jh/user/project/import/gitee.html https://docs.gitlab.cn/jh/user/project/settings/import_export.html https://docs.gitlab.com/ee/raketasks/import.html https://docs.gitlab.cn/ee/raketasks/import.html

先想着能不能都pull下来,然后就可以拷到gitlab对应目录中,运行一下gitlab-rake迁移命令就完事。也就是:https://docs.gitlab.cn/ee/raketasks/import.html 或 https://www.kancloud.cn/apachecn/gitlab-doc-zh/1949085 中的方法。可惜已经废弃了。docker中装了下低版本的gitlab,试了下也不好使,不成功。

然后看到StackOverflow上https://stackoverflow.com/questions/75224739/add-bare-git-repositories-to-gitlab 说:

用git push就好了。

Interesting that it doesn't mention it as part of the deprecation notice, but you could write a simple script that loops through all your repositories and creates the project through git push.

If you take a look at the Create a new project with Git push documentation, that should cover the use case you've described.

If you need to create the projects in different namespaces and those don't exist, then you'll need to create a group via API as part of your script.

比如 git push -f ssh://ole12138.top:9922/abc/xxx.git master ,其中abc是gitlab上提前定义好的user或group。

试了下,可以push到自己的gitlab。但是只push了master分支。去掉master,结果默认也是只push了master分支。

网上有说 git push -f --all REMOTE 这里的remote 是上面定义好的gitlab链接,不好使。

还有说 git push -f REMOTE '*:*' 这里的remote 是上面定义好的gitlab链接,不好使。

然后看到了这个:https://stackoverflow.com/questions/34265266/remote-rejected-errors-after-mirroring-a-git-repository

git clone --bare https://github.com/exampleuser/repository-to-mirror.git

cd repository-to-mirror.git

git push --mirror https://github.com/exampleuser/mirrored

对应的地址改成gitee和gitlab的就行。但还是要自己写个脚本,循环执行一下。

最终实现

下面是写好的脚本:

[root@archlinux tmp_clone]# cat ./clone.sh 
#!/bin/bash

TMP_DIR=$(readlink -f ./)
GITEE_PREFIX="git@gitee.com:woyunsoft"
GITLAB_PREFIX="ssh://ole12138.top:9922/yak"
REPOS_FILE="./repos.txt"
SSH_KEY="./id_rsa3"


echo "TMP_DIR=$TMP_DIR"
echo "GITEE_PREFIX=$GITEE_PREFIX"
echo "GITLAB_PREFI=X$GITLAB_PREFIX"


# set ssh-agent, and use the given ssh-key
eval `ssh-agent -s`
ssh-add $SSH_KEY

cat $REPOS_FILE | \
while read line
do
    echo "cd $TMP_DIR"
    cd $TMP_DIR

    echo "line=$line"

    repo_name="${line%.*}"
    echo "repo_name=$repo_name"

    gitee_remote="${GITEE_PREFIX}/${repo_name}.git"
    echo "gitee_remote=$gitee_remote"
    
    gitlab_remote="${GITLAB_PREFIX}/${repo_name}.git"
    echo "gitlab_remote=$gitlab_remote"

    echo "git clone --bare $gitee_remote"
    git clone --bare $gitee_remote

    echo "cd ${repo_name}.git"
    cd ${repo_name}.git

    echo "git push --mirror $gitlab_remote"
    git push --mirror $gitlab_remote

    echo "cd $TMP_DIR"
    cd $TMP_DIR

    echo "rm -rf ${repo_name}"
    rm -rf ${repo_name}.git

    echo
    echo
    echo
done

主要涉及三个文件:

  • 这个脚本clone.sh,
  • 同目录下存放所有repositories名称的repos.txt
  • 用于连接gitee和gitlab的密钥对中的私钥id_rsa3。(gitee和gitlab上都以事先上传了此密钥对中的公钥id_rsa3.pub)

快写完此脚本的时候,发现别人已经写过了类似的代码了。。。,而且一看就逻辑清晰。

这个:https://juejin.cn/post/7207411012487217211


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注