Skip to content

Instantly share code, notes, and snippets.

@alwalker
Created January 11, 2021 14:51
Show Gist options
  • Save alwalker/fd3c19b2c0a751197c7629a840cc33ce to your computer and use it in GitHub Desktop.
Save alwalker/fd3c19b2c0a751197c7629a840cc33ce to your computer and use it in GitHub Desktop.
Search current directory for git repos and generate script to recreate them.
set -e
echo "set -e" > gitbuilder.sh
dirs=()
readarray -d '' dirs < <(find . -name .git -type d -prune)
for dir in ${dirs[@]}; do
cleandir=$(echo $dir | sed 's/\.git//')
remote=$(git --git-dir=$dir remote -v | grep fetch | sed -r 's/origin\s+//' | sed -r 's/\s+\(fetch\)//')
echo "" >> gitbuilder.sh
echo "mkdir -p $cleandir" >> gitbuilder.sh
echo "git clone $remote $dir">> gitbuilder.sh
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment