Skip to content

Instantly share code, notes, and snippets.

@jasonish
Created November 14, 2012 15:15
Show Gist options
  • Save jasonish/4072695 to your computer and use it in GitHub Desktop.
Save jasonish/4072695 to your computer and use it in GitHub Desktop.
Script to backup your git repos and optionally push them to another remote.
#! /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