Last active
January 1, 2024 13:03
-
-
Save luoq/aa7695875c54f61acaa679f4f5b77c5b to your computer and use it in GitHub Desktop.
backup git repos under a directory
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
#!/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