Skip to content

Instantly share code, notes, and snippets.

@derrekbertrand
Created November 25, 2025 23:40
Show Gist options
  • Select an option

  • Save derrekbertrand/0809ff861da1234f69b02654304942bd to your computer and use it in GitHub Desktop.

Select an option

Save derrekbertrand/0809ff861da1234f69b02654304942bd to your computer and use it in GitHub Desktop.
Server Git Hooks
#!/bin/bash
# todo: single commit? CI stuff?
while read old_commit new_commit ref
do
if [ "$old_commit" == "0000000000000000000000000000000000000000" ]; then
range=$new_commit
else
range=$old_commit..$new_commit
if [ "$ref" == "refs/heads/main" ] && ! git merge-base --is-ancestor "$ref" "$new_commit"; then
echo "$ref is a protected branch"
exit 1
fi
fi
if [[ $(git rev-list --merges $range) ]]; then
echo "$ref contains merge commits; please rebase"
exit 1
fi
if ! git rev-list $range | xargs git verify-commit; then
echo "$ref has unsigned commits in range $range; please sign your commits"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment