Prevent pulling / pushing from an outdated Git repository and redirecting to a new one

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

+3


source to share


1 answer


You can do this using the "pre-receive" hook. You need to create a file named pre-receive

in the old repo directory .git/hooks

. Make sure it is executable ( sudo chmod +x pre-receive

) and set the file content 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.

0


source







All Articles