Skip to content

Instantly share code, notes, and snippets.

@tadas-s
Created September 5, 2013 11:13
Show Gist options
  • Save tadas-s/6448825 to your computer and use it in GitHub Desktop.
Save tadas-s/6448825 to your computer and use it in GitHub Desktop.
A small bash script function to check if local git repository copy has changes. I use it for some deployment automation scripts.
#!/bin/bash
#
# Checks if git repository at $1 does not have modified files
#
function is_dirty {
GIT_DIR="$1/.git" GIT_WORK_TREE="$1" git diff --quiet
if [[ $? == 0 ]]; then
return 1
else
return 0
fi
}
# usage example
is_dirty $1 && echo "$1 is dirty!" && exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment