Skip to content

Instantly share code, notes, and snippets.

@ngandrass
Created February 8, 2018 14:01
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 ngandrass/5675be09015808cde177e69524449241 to your computer and use it in GitHub Desktop.
Save ngandrass/5675be09015808cde177e69524449241 to your computer and use it in GitHub Desktop.
Mirror and update git/GitHub repository mirrors via a bash script
#!/usr/bin/env bash
# Updates all git repository mirrors that sit in current
# directory with a folder name ending on .git.
#
# Also allows to add repositories. See usage.
#
# To remove a mirrored repository simply delete the folder.
function print_usage() {
echo "Usage: update_github_mirrors.sh [add REPO_URL]"
exit 1
}
if [[ $# -eq 0 ]]; then
for cur_dir in $(ls -d *.git); do
echo "-> Updating ${cur_dir}"
pushd ${cur_dir} > /dev/null
git remote prune origin
git remote update -p
popd > /dev/null
echo ""
done
echo "Updated all repositories"
elif [[ $# -eq 2 ]]; then
if [[ "$1" == "add" ]]; then
git clone --mirror "$2"
else
print_usage
fi
else
print_usage
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment