-
-
Save jannson/2a36b949ed3ac98ff9425ecaf897056c to your computer and use it in GitHub Desktop.
Script to backup your git repos and optionally push them to another remote.
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
#! /bin/sh | |
# | |
# Script to backup git repositories. | |
# | |
# For each subdirectory ending in .git: | |
# - perform a git fetch from origin. | |
# - perform a git push --all to all remotes other than origin. | |
repos=`find * -type d -name \*.git` | |
fetch_repo() { | |
repo="$1" | |
git --git-dir "${repo}" fetch origin | |
} | |
push_repo() { | |
repo="$1" | |
for remote in `git --git-dir "${repo}" remote | grep -v origin`; do | |
echo "Pushing to ${remote}..." | |
git --git-dir "${repo}" push --all ${remote} | |
done | |
} | |
for repo in ${repos}; do | |
echo "Updating ${repo}..." | |
fetch_repo "${repo}" | |
push_repo "${repo}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment