Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created June 16, 2012 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naiquevin/2940530 to your computer and use it in GitHub Desktop.
Save naiquevin/2940530 to your computer and use it in GitHub Desktop.
Setting up and maintaining Git repository mirrors
#!/bin/bash
## This shell script will read all names from repos.txt
## which are names of git repositories located at
## git@main-reposerver:/path/to/repos
## if a mirror is not created, it will create
##
## other wise it will try to update the mirror
##
## Main purpose of having mirrors is backup so pushing
## changes to main repo is disabled by default. To enable
## it, uncomment the two lines below
for repo in `cat repos.txt`
do
rdir="/home/git/mirrors/$repo"
if [ -d $rdir ]; then
echo "Mirror for $repo found.."
echo "Fetching updates from main repo.."
`cd $repo && git remote update`
# echo "Pushing updates to main repo"
# `cd $repo && git push --mirror`
else
echo "Mirror for $repo not found.."
echo "Creating a mirror.."
`git clone --mirror git@main-reposerver:/path/to/repos/$repo`
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment