Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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