简体   繁体   中英

Prevent pull/push from an obsolete Git repo and redirect to a new one

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM