从GitHub迁移到GitLab(作为POSIX环境中的遥控器)

CPB*_*PBL 4 linux git github find gitlab

我正在迁移到GitLab.我需要编辑包含"github"的工作站上的所有.git/config文件,并用"gitlab"替换该单词.我怀疑这可以通过一个find命令最轻松地完成,而不是git在每个文件夹中使用一个调用.

我想它会是这样的:

find ./ -name ".git/config" -type f -exec sed -i 's/github/gitlab/gI' {} \;
Run Code Online (Sandbox Code Playgroud)

这是一种安全/合理的方法吗?做这个的最好方式是什么?

编辑/更新:评论:我实际上不想为所有github repos做那个,因为它只是我控制的那些正在移动.我没有修改我的问题,但接受的答案包括仅针对一个github帐户的版本.我自己的答案下面最实际的是完成了改变每个文件的目标.

Von*_*onC 5

你没有,你可以使用一个单一的规则与一个insteadOf指令.

git config --global url."https://gitlab.com/".insteadOf "https://github.com/"
git config --global url."git@gitlab.com:".insteadOf "git@github.com:"
Run Code Online (Sandbox Code Playgroud)

然后,任何git push/pull/clone使用github.comURL的人都会使用gitlab.com.

OP中华职棒提到的评论:

为了不更改我使用的其他GitHub包,以下内容适用于我:

git config --global url."git@gitlab.com:cpbl".insteadOf "git@github.com:cpbl"
git config --global url."git@gitlab.com/cpbl".insteadOf "git@github.com/cpbl"
Run Code Online (Sandbox Code Playgroud)