Check if git has files that are not checked in (dirty)


If you need to check if a repo has files that need to be committed:

Only modified files:

if [[ $(git diff --stat) != '' ]]; then
  echo 'dirty'
else
  echo 'clean'
fi

Only new files:

if [[ $(git status --short | grep "??" ) != '' ]]; then
  echo 'dirty'
else
  echo 'clean'
fi

Either new or modified files:

if [[ $(git status --short) != '' ]]; then
  echo 'dirty'
else
  echo 'clean'
fi

source

Date: 2021-12-23

Tags:  git

Share: