Skip to content

Instantly share code, notes, and snippets.

@initbar
Created July 14, 2022 15:01
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 initbar/46294ffdd33c425ea9786f29c74dc46f to your computer and use it in GitHub Desktop.
Save initbar/46294ffdd33c425ea9786f29c74dc46f to your computer and use it in GitHub Desktop.
#!/bin/bash
{
for i in $(ls | shuf); do
[ -d "$i" ] && {
[ -d "$i/.git" ] && (
cd "$i"
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${branch}" == 'main' || "${branch}" == 'master' ]]; then
:
else
git reset --hard HEAD
git checkout main || git checkout master
fi
while :; do
echo -e ">>> Syncing\t$i: ${branch}"
{
git reset --hard HEAD &&\
git pull origin HEAD
} &> /dev/null
[[ $? == 0 ]] && {
echo -e "<<< Synced\t$i"
echo '---'
break
}
echo -e "<<< Retrying\t$i"
sleep 5
done
)
}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment