#!/bin/bash
current_branch="$(git symbolic-ref --short HEAD)"
FORBIDDEN_BRANCHES=(master develop)
for forbidden_branch in "${FORBIDDEN_BRANCHES[@]}"; do
if [ "$current_branch" == "$forbidden_branch" ]; then
echo 'You are not allowed to commit in this branch.'
exit 1
fi
done
- Copy the content of this hook in
/your/project/.git/hooks/pre-commit
- Make the pre-commit hook executable
chmod +x /your/project/.git/hooks/pre-commit