Skip to content

Instantly share code, notes, and snippets.

@pjbgf
Last active January 30, 2024 15:46
Show Gist options
  • Save pjbgf/45048d8e3688fc070c7667f4b8f10374 to your computer and use it in GitHub Desktop.
Save pjbgf/45048d8e3688fc070c7667f4b8f10374 to your computer and use it in GitHub Desktop.
Check for local changes in any git repositories under the current working dir
#!/bin/bash
set -eo pipefail
VERBOSE="${VERBOSE:-false}"
dirs=$(find -mindepth 1 -maxdepth 10 -type d -name .git)
for dir in $dirs; do
dir=$(dirname $dir)
pushd "$dir" > /dev/null
prefix="⚠️"
if [[ "${VERBOSE}" == "true" ]]; then
echo "Checking Git repository in $dir:"
else
prefix="$dir:"
fi
# Check for unpushed commits
if [[ $(git log --branches --not --remotes) ]]; then
echo "${prefix} Unpushed commits ahead of remote!"
fi
# Check for dirty worktree
if [[ `git status --porcelain` ]]; then
echo "${prefix} Uncommitted changes in worktree!"
fi
popd > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment