Created
February 8, 2018 14:01
-
-
Save ngandrass/5675be09015808cde177e69524449241 to your computer and use it in GitHub Desktop.
Mirror and update git/GitHub repository mirrors via a bash script
This file contains hidden or 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
#!/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