Skip to content

Instantly share code, notes, and snippets.

@Prinzhorn
Created November 11, 2013 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prinzhorn/7411142 to your computer and use it in GitHub Desktop.
Save Prinzhorn/7411142 to your computer and use it in GitHub Desktop.
pre-push hook to prevent pushing when untracked files are present. i.e. breaking your production server because you forgot to add a new file in your commit and the tests run locally inside the repo.
git status --porcelain | grep '^??'
rc=$?
#grep exits with 0 when a match is found.
if [ $rc = 0 ] ; then
echo "Untracked files present. Aborting push.";
exit 1;
fi
exit 0;
@FBerthelot
Copy link

Hello,
Your gist helped me, thanks !
I think, i've improved it

if [[ $(git status --porcelain) ]]; then
   echo "Uncommited  files present. Aborting push.";
   exit 1;
fi

Plus, git status --porcelain is not only for untracked file but also for uncommited files 😸

Bye,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment