Skip to content

Instantly share code, notes, and snippets.

@mijdavis2
Forked from jcromartie/pre-commit
Last active June 2, 2021 21:18
Show Gist options
  • Save mijdavis2/09b6ff4e082faa3e3416d3e663084dd7 to your computer and use it in GitHub Desktop.
Save mijdavis2/09b6ff4e082faa3e3416d3e663084dd7 to your computer and use it in GitHub Desktop.
Git pre-commit hook to help stay up-to-date with master
#!/usr/bin/env bash
# hook to enforce that current branch is up-to-date with latest
# changes from master before committing
# put me in .git/hooks and make me executable
# the output of rev-list in the following test will be empty if there
# are no commits in master that aren't in the current branch
git fetch
if [ ! -z "$(git rev-list ..master)" ]
then
echo "abandoning commit"
echo "please rebase from master and try again"
echo " git fetch; git rebase origin/master"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment