3

We are moving a Git repository to a new server. After migration we could obviously just delete the old repository, so when people try to push or pull they get an error and look up the new repository URL on the wiki, but is it possible to instead prevent pull and push and show the new URL in the error message?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

0

You can do this using a "pre-receive" hook. You'll need to create a file called pre-receive in the old repo's .git/hooks directory. Make sure it's executable (sudo chmod +x pre-receive), and set the content of the file to something like this:

echo;
echo "This is the old master repo.";
echo "The repo has been moved. Please update 'origin' accordingly:";
echo;
echo "git remote set-url origin user@new-server.com:/path/to/new/repo.git"
echo;

# Reject the push:
exit 1;

Now when someone tries to push to the old repo, it will return the above message and reject the push.

Nick F
  • 9,781
  • 7
  • 75
  • 90