Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving to GitLab from GitHub (as remotes in POSIX environment)

I'm migrating to GitLab. I need to edit all the .git/config files on my workstations which contain "github" and replace that word with "gitlab". I suspect that this can be done most easily with a single find command, rather than using a git call in each folder.

I think it would be something like:

find ./ -name ".git/config" -type f -exec sed -i 's/github/gitlab/gI' {} \;

Is this a safe/reasonable approach? What is the best way to do this?

Edit/Update: Comment: I actually do not want to do that for all github repos, since it is only the ones I control which are moving. I haven't revised my question, but the accepted answer includes a version to target only one github account. And my own answer below most literally accomplishes the goal of changing every file.

like image 806
CPBL Avatar asked Mar 07 '23 01:03

CPBL


1 Answers

You don't have to, you can use a single rule with an insteadOf directive.

git config --global url."https://gitlab.com/".insteadOf "https://github.com/"
git config --global url."[email protected]:".insteadOf "[email protected]:"

Then, any git push/pull/clone using a github.com URL would use gitlab.com instead.

The OP CPBL mentions in the comments:

So as not to change other GitHub packages I use, the following works for me:

git config --global url."[email protected]:cpbl".insteadOf "[email protected]:cpbl"
git config --global url."[email protected]/cpbl".insteadOf "[email protected]/cpbl"
like image 112
VonC Avatar answered Mar 23 '23 09:03

VonC