Created
August 7, 2024 10:59
-
-
Save rokiden/cbe0be92b458f6d6e8501033721fb4f3 to your computer and use it in GitHub Desktop.
Git mirror from one remote server to another through local or readonly mirror using Nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo docker run --name gitmir -v $PWD:/usr/share/nginx/html:ro nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from remote server to local for dumb http server | |
if [ "$#" -ne 0 ] && [ "$#" -ne 1 ]; then | |
echo "Invalid number of arguments." | |
echo "Usage: $0 [source_repo_url mirror_repo_url]" | |
exit 1 | |
fi | |
if [ "$#" -eq 1 ]; then | |
git clone --mirror $1 && \ | |
cd "$(basename "$_" .git).git" && \ | |
for ref in $(git for-each-ref --format='%(refname)' refs/pull/); do \ | |
git update-ref -d $ref; \ | |
done \ | |
else | |
git fetch origin '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*'; \ | |
fi && \ | |
git update-server-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from one remote server to another through local | |
if [ "$#" -ne 0 ] && [ "$#" -ne 2 ]; then | |
echo "Invalid number of arguments." | |
echo "Usage: $0 [source_repo_url mirror_repo_url]" | |
exit 1 | |
fi | |
if [ "$#" -eq 2 ]; then | |
git clone --mirror $1 && \ | |
cd "$(basename "$_" .git).git" && \ | |
git remote add mirror $2 && \ | |
for ref in $(git for-each-ref --format='%(refname)' refs/pull/); do \ | |
git update-ref -d $ref; \ | |
done \ | |
else | |
git fetch origin '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*'; \ | |
fi && \ | |
git push mirror 'refs/heads/*' 'refs/tags/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to update all mirrors in working dir | |
for d in *.git; do | |
echo $d && \ | |
cd $d && \ | |
../mirror_repo.sh && \ | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment