├── README.md └── gitcheck /README.md: -------------------------------------------------------------------------------- 1 | # gitcheck 2 | 3 | Searches and checks Git repositories for uncommited files, staged changes, 4 | untracked files, and branches not pulled/pushed. 5 | -------------------------------------------------------------------------------- /gitcheck: -------------------------------------------------------------------------------- 1 | #!/bin/bash -u 2 | 3 | status() { 4 | echo $1 5 | if git log -n1 >/dev/null 2>/dev/null; then 6 | git diff --quiet || echo -e "\tworkdir is \e[1;33mDIRTY\e[0m" 7 | git diff-index --quiet --cached HEAD -- || echo -e "\tchanges are \e[1;33mCACHED\e[\0m" 8 | else 9 | echo -e "\t\e[1;34mHEAD\e[0m has no commits" 10 | fi 11 | untracked=$(git ls-files --exclude-standard --others | wc -l) 12 | [ $untracked == 0 ] || echo -e "\t\e[1;35m$untracked\e[0m file(s) are \e[1;33mUNTRACKED\e[0m" 13 | remotes=() 14 | for branch in $(cd .git/refs/heads; ls); do 15 | remote=$(git config branch.$branch.remote) 16 | if [ -z "$remote" ]; then 17 | echo -e "\t\e[1;34m${branch}\e[0m has no \e[1;33mUPSTREAM\e[0m" 18 | else 19 | remotes+=($remote) 20 | fi 21 | done 22 | 23 | 24 | for remote in $(echo ${remotes[*]} | xargs -n1 | sort -u); do 25 | git fetch --quiet $remote 26 | done 27 | 28 | for branch in $(cd .git/refs/heads; ls); do 29 | remote=$(git config branch.$branch.remote) 30 | if [ -n "$remote" ]; then 31 | upstream=$(basename $(git config branch.$branch.merge)) 32 | behind=$(git log "$branch".."$remote/$upstream" --oneline | wc -l) 33 | ahead=$(git log "$remote/$upstream".."$branch" --oneline | wc -l) 34 | [ $behind == 0 ] || echo -e "\t\e[1;34m$branch\e[0m is \e[1;35m$behind\e[0m commit(s) \e[1;33mBEHIND\e[0m \e[1;34m$remote/$upstream\e[0m" 35 | [ $ahead == 0 ] || echo -e "\t\e[1;34m$branch\e[0m is \e[1;35m$ahead\e[0m commit(s) \e[1;33mAHEAD\e[0m of \e[1;34m$remote/$upstream\e[0m" 36 | fi 37 | done 38 | } 39 | 40 | status_all() { 41 | while read path; do 42 | workdir=$(dirname "$path") 43 | (cd $workdir;status "$workdir") 44 | done 45 | } 46 | 47 | find -type d -name .git | status_all 48 | --------------------------------------------------------------------------------