Skip to content

Instantly share code, notes, and snippets.

@jannson
Forked from jasonish/git-backup.sh
Created November 30, 2022 08:19
Show Gist options
  • Save jannson/2a36b949ed3ac98ff9425ecaf897056c to your computer and use it in GitHub Desktop.
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.
#! /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