Skip to content

Instantly share code, notes, and snippets.

@luoq
Last active January 1, 2024 13:03
Show Gist options
  • Save luoq/aa7695875c54f61acaa679f4f5b77c5b to your computer and use it in GitHub Desktop.
Save luoq/aa7695875c54f61acaa679f4f5b77c5b to your computer and use it in GitHub Desktop.
backup git repos under a directory
#!/bin/bash
set -eu
src_root=$1
dst_root=$2
max_depth=${3:-5}
cd $src_root
for repo in $(find . -maxdepth $max_depth -type d -name .git); do
repo=$(dirname $repo)
echo "backup $repo"
dst_repo=$dst_root/${repo}.git
[ -d $dst_repo ] || ( mkdir -p $dst_repo && git clone --mirror $repo $dst_repo )
git --git-dir $dst_repo remote update
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment