gitgitlabgit-remote

Can you easily spread Git remote url changes to all developers?


So this is fairly similar in nature to this old question regarding obtaining all remotes when cloning a repository.

For context, I am required to transfer about 30 projects from an old git forge to a newer, shinier GitLab instance. To make this as transparent as possible for the developers, I was planning on a 2-step approach :

  1. Set-up their local repositories to have the origin remote point to the old instance for fetching and both the old and new ones for pushing, creating a sort of "mirror" on the new instance. This would ease them into using the web interface and give them time to set up SSH keys and the lot and make the slow transition from one tool to the other ;
  2. Then, switch to the new instance for fetching and slowly phase out the old git.

This was my initial approach because we have some external contractors and some old projects lying around, and I was concerned that an overnight shift to the new GitLab would cause more trouble than it's worth...

Only now did I realise that changes to the remote urls are only local. This would mean that to implement step 1 of my plan, every dev would have to run git remote --set-url --add --push origin git@xxxxx:repo.git for every project, which would be a nightmare as some would inevitably slip through the cracks. I initially thought that adding an URL to the remote would add it to the repo's config, which would then be updated on every other dev's local copy.

My question is in two parts - Firstly, is there still no way to this day to make it so that changes to the remote configuration are spread to all users when they next clone/fetch a project? And if not, how could I set up this transition to the new remote smoothly?

I feel like I may not be going at this the right way. In any case, asking 20ish developers to run a command on 30 projects each is not gonna fly.


Solution

  • give them time to set up SSH keys

    If you have access to the old account database, batch pre-create users and import keys from the old system.

    is there still no way to this day to make it so that changes to the remote configuration are spread to all users when they next clone/fetch a project?

    No, probably even deliberately so (if I had to guess). The HTTP client code honors temporary redirects but SSH doesn't, likely because an SSH connection could have more security impact (e.g. implicitly revealing user's default public keys, which could be different than the key configured for the Git host).

    every dev would have to run git remote --set-url --add --push origin git@xxxxx:repo.git for every project

    Have them run a git config that adds an insteadOf alias.

    git config --global url."git@newhost:".insteadOf "git@oldhost:"
    

    (Any prefix works, e.g. git@oldhost:myorg/ if it was a specific organization's repos.)