Skip to content

Instantly share code, notes, and snippets.

@arne-cl
Created December 11, 2018 19:49
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 arne-cl/c7079d8a5a4c26cc15655575f0b72807 to your computer and use it in GitHub Desktop.
Save arne-cl/c7079d8a5a4c26cc15655575f0b72807 to your computer and use it in GitHub Desktop.
List all git repositories with uncommitted code / unpushed commits in the current dir
#!/bin/bash
# This script lists all git repositories in the current directory
# that contain uncommited code or have unpushed commits.
# recursively list all directories (three levels deep) that don't have
# '.git' in their path.
#
# 'while read LINE' and 'cd "$LINE"' are used to handle paths that
# would need escaping.
find ./ -maxdepth 3 -type d | grep -v /\.git | while read LINE; do
( # start subshell
cd "$LINE" && \
result=`git cherry -v 2>/dev/null`; rc=$? && \
# if the stdout of git-cherry is not an empty string
if [ -n "$result" ]; then
echo $(pwd)
fi
) # end subshell
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment