Skip to content

Instantly share code, notes, and snippets.

@tristanlins
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanlins/9504609 to your computer and use it in GitHub Desktop.
Save tristanlins/9504609 to your computer and use it in GitHub Desktop.
Script to find GIT repositories that have modified files and unpublished commits.
#!/bin/bash
BASEDIR=$(pwd)
find -type d -name .git | while read GITDIR; do
DIR=$(dirname $GITDIR)
cd "$BASEDIR/$DIR"
STATUS=$(git status -s)
if [[ -n "$STATUS" ]]; then
echo '--- modifications --------------------------------------------------------------'
pwd
echo
git status -s
echo
fi
LOCAL_BRANCH=$(git symbolic-ref HEAD 2>/dev/null)
LOCAL_BRANCH=${LOCAL_BRANCH#refs/heads/}
if [[ -n "$LOCAL_BRANCH" ]]; then
REMOTE=$(git config branch.$LOCAL_BRANCH.remote)
REMOTE_BRANCH=$(git config branch.$LOCAL_BRANCH.merge)
REMOTE_BRANCH=${REMOTE_BRANCH#refs/heads/}
if [[ -n "$REMOTE" ]]; then
git fetch --quiet "$REMOTE"
LOG=$(git --no-pager log --oneline "$REMOTE/$REMOTE_BRANCH..$LOCAL_BRANCH")
if [[ -n "$LOG" ]]; then
echo '--- unpublished commits --------------------------------------------------------'
pwd
echo
git --no-pager log --oneline "$REMOTE/$REMOTE_BRANCH..$LOCAL_BRANCH"
echo
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment