Skip to content

Instantly share code, notes, and snippets.

@erincerys
Created October 5, 2025 13:55
Show Gist options
  • Save erincerys/117c08b14687c3ba355d74843465b225 to your computer and use it in GitHub Desktop.
Save erincerys/117c08b14687c3ba355d74843465b225 to your computer and use it in GitHub Desktop.
Recursively traverses directories to update Git repositories from remote
#!/bin/bash
#
# DESCRIPTION:
# iterates through a directory and its subdirectories
# updating any git repositories from remote
#
set +e
for d in *; do
if [[ -d "$d" && -d "${d}/.git" ]]; then
cd "$d" || continue
else
continue
fi
echo -e "Processing ${d}\n"
ORIGIN_URL=$(git remote get-url origin | sed 's/.git$//')
# Handle onion sites
if [[ "$ORIGIN_URL" =~ \.onion ]]; then
if ! command -v torsocks; then
echo -e "Repository hosted on an onion site, but torsocks not available.\n"
cd - >/dev/null || exit 1
continue
fi
HTTP_CODE=$(torsocks curl -s -I "$ORIGIN_URL" | head -n 1 | awk '{ print $2 }')
if [ "$HTTP_CODE" -eq 200 ]; then
{ torsocks git fetch --porcelain && torsocks git pull; }; echo
fi
# Handle clearnet sites
else
if [[ "$ORIGIN_URL" =~ bitbucket\.org:vigorsystemsinc ]]; then
echo -e "Skipping excluded repository\n"
elif [[ "$ORIGIN_URL" =~ git\.codemadness\.org ]]; then
{ git fetch --porcelain && git pull; }; echo
else
HTTP_CODE=$(curl -s -I "$ORIGIN_URL" | head -n 1 | awk '{ print $2 }')
if [ "$HTTP_CODE" -eq 200 ]; then
{ git fetch --porcelain && git pull; }; echo
else
test -n "$HTTP_CODE" && echo -e "Received $HTTP_CODE" >&2
echo -e "See $ORIGIN_URL for details\n" >&2
fi
fi
fi
cd - >/dev/null || exit 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment