Configure as variáveis SRC e DEST , por exemplo:
SRC="./"
DEST="../BACKUP/"
Você pode usar algo como find para localizar todos os diretórios .git :
find "${SRC}" -type d -name '.git'
Isso incluirá ${SRC}/.git também (o que se tornará ${SRC} e, portanto, ignorará " tudo ") ... para evitar esse uso -mindepth 2 :
find "${SRC}" -mindepth 2 -type d -name '.git'
Em seguida, retire os componentes /.git finais:
find "${SRC}" -mindepth 2 -type d -name '.git' \
| sed -re 's!/.git$!!g'
Como rsync definirá seu diretório de trabalho para a origem, também precisamos cortar o ${SRC} inicial dos resultados:
find "${SRC}" -mindepth 2 -type d -name '.git' \
| sed -re 's!^'"${SRC}"'!!g;s!/.git$!!g'
Por fim, junte-se a isso com o comando rsync , usando --exclude-from , passando - (ou seja, stdin ):
find "${SRC}" -mindepth 2 -type d -name '.git' \
| sed -re 's!^'"${SRC}"'!!g;s!/.git$!!g' \
| rsync -av --exclude-from - "${SRC}" "${DEST}"/
OBSERVAÇÃO: isso não selecionará nenhum arquivo não rastreado / modificado.