1

Every answer about migrating git repo says:

git clone --mirror git@github/odlrepo.git
git push --mirror git@github/newrepo.git

But nobody says, what to do after...

How to force developers to use newrepo?

Solutions that I came with are:

  • git hook on oldrepo which will push changes to newrepo (but if developers keep pushing to both - it seems like its asking for troubles)
  • git hook which blocks commits and says "change remote, we are using now newrepo

But maybe there are some better solutions?

ravenwing
  • 668
  • 3
  • 20
  • 4
    AFAIK, blocking commits and telling users to change their remote URL is the best way to go with this. – iBug Mar 11 '21 at 18:11
  • 1
    You can write a `pre-push` hook for your older repository(assuming it is still active). You may create a `pre-push` hook script that sets the remote. The best bet should be setting the remote "origin" which also happens to be a default remote name and will cover most developers unless the developers changed the default remote name from `origin` to something else. This still is not fool proof, but might well come in handy. – Asif Kamran Malick Mar 11 '21 at 18:48
  • @AsifKamranMalick whoah! Is that even possible? It seems like a big security issue. How much can pre-push hooks do? – ravenwing Mar 12 '21 at 11:12
  • @ravenwing Thanks for the reminding. My bad. It turns out that the `pre-push` hook is a client-side hook. So not much luck here. As per my experience though they work locally since they take the remote name and url as parameters. But again, they are not server-side hooks. So it appears your best bet is to follow iBug and VonC's suggestions by implementing branch protection rules in your older repo. – Asif Kamran Malick Mar 12 '21 at 15:00
  • I think your second option "git hook which blocks commits and says "change remote, we are using now newrepo" is a good one. That's what I would do. – Mort Mar 19 '21 at 02:04

1 Answers1

1

Without having to manage hooks, you could:

  • protect your old repo branches in order to disable any push
  • empty the content of the master branch to leave only a README which clearly explain the situation, asking for developers to now clone from or push to the new repository.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250