Tip: Prevent git from commiting to master/develop/stable branches

Happy Friday! Happy Thanksgiving!

$ cat .git/hooks/pre-commit
#!/bin/bash
branch="$(git rev-parse --abbrev-ref HEAD)"

if [[ "$branch" == "master" || "$branch" == "develop" || "$branch" == *-stable ]]; then
  echo "You can't commit directly to master/stable/develop branch"
  exit 1
fi

You are welcome.

3 Likes

Love it! thanks :heart:

1 Like