Skip to content

Instantly share code, notes, and snippets.

@ewoutvonk
ewoutvonk / git-dirty-oneliner.bash
Created July 7, 2011 09:04
Check dirtyness of git repository (working directory dirtyness, untracked files in working directory, unpushed commits, existing stashes, non-existing branches on remote origin)
echo "$(basename $(pwd))..." ; git branch -a 2>/dev/null | cut -c 3- | perl -p -e 's#remotes/origin/##' | awk '{ print $1; }' | grep -v "remotes" | sort | uniq -c | awk '{ if($1=="2") { print $2; } ; }' | while read b ; do { [ ! -z "$(git cherry remotes/origin/$b $b 2>/dev/null)" ] && echo "$(basename $(pwd)): branch ${b} has unpushed commits" ; } ; done ; git branch -a 2>/dev/null | cut -c 3- | perl -p -e 's#remotes/origin/##' | awk '{ print $1; }' | grep -v "remotes" | sort | uniq -c | awk '{ if($1=="1") { print $2; } ; }' | while read b ; do { [ -z "$(git branch -a | cut -c 3- | awk -v branch="remotes/origin/${b}" '{ if($1==branch) { print $1; } ; }')" ] && echo "$(basename $(pwd)): branch ${b} does not exist on remote origin" ; } ; done ; [ ! -z "$(git status --porcelain -uno 2>/dev/null)" ] && echo "$(basename $(pwd)): working directory is dirty" ; [ ! -z "$(git status --porcelain -uall 2>/dev/null | perl -n -e 'm/^\?\?/ && print')" ] && echo "$(basename $(pwd)): working directory contains untracked file