Skip to content

Instantly share code, notes, and snippets.

View mayrmt's full-sized avatar

Matthias Mayr mayrmt

View GitHub Profile
@mayrmt
mayrmt / pre-commit
Last active April 13, 2023 06:39
Pre-commit hook to enforce use of feature branches and reject commits to master
#!/bin/bash
# This pre-commit hook prevents commits on branch '<forbidden_branch>' and enforces the use of feature branches.
# To use it in your repository, follow these steps:
# 1. Copy this file to `.git/hooks/pre-commit`
# 2. Make the file executable, e.g. via `chmod u+x .git/hooks/pre-commit`
#
# If one wants to commit to the '<forbidden_branch>' branch, the commit is rejected (script exits 1).
# The user is asked to create and checkout a new feature branch in order to proceed with the commit.
#