Skip to content

Instantly share code, notes, and snippets.

@debuglevel
Created February 20, 2019 12:54
Show Gist options
  • Save debuglevel/3b036e7617e6a85294fdd7db2bda900f to your computer and use it in GitHub Desktop.
Save debuglevel/3b036e7617e6a85294fdd7db2bda900f to your computer and use it in GitHub Desktop.
bash script which checks if all subdirectories are git repositories with a origin remote set
#!/bin/bash
for dir in */ ; do
echo -ne "$dir \t "
git -C "$dir" rev-parse &> /dev/null
CODE=$?
if [[ "$CODE" -eq "0" ]]; then
echo -ne "is a git repository "
git -C "$dir" remote get-url origin &> /dev/null
CODE=$?
if [[ "$CODE" -eq "0" ]]; then
ORIGIN_URL=$(git -C "$dir" remote get-url origin)
echo -e "with origin at \t $ORIGIN_URL"
else
echo -e "with NO origin"
fi
else
echo "is NOT a git repository"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment