Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created September 17, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/3b0071b821f4380f215841650fa8129c to your computer and use it in GitHub Desktop.
Save abdennour/3b0071b821f4380f215841650fa8129c to your computer and use it in GitHub Desktop.
Backup All Git Repos with All branches
#!/bin/bash
team=${1};
repos_list_file=${2};
while read repo; do
if [[ ! -d "$repo" ]]; then
echo $repo clone...
git clone git@bitbucket.org:${team}/${repo}.git;
TIMEOUT=$((5 + RANDOM % 10));
echo cloning next repo starts after $TIMEOUT seconds;
sleep $TIMEOUT;
else
cd $repo;
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git pull --all
cd ../;
fi
done < ${repos_list_file}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment