Prevent commiting on protected branches (e.g. master)
First protect those branches on your GitLab repository:
- Find Project Settings - Repository - Protected Branches and press Expand.
- Choose a branch like "master" in the drop-down list "Branch".
- Set "Allow to push" to "No one".
Now you can protect those branches in your local repository as well:
- Add this snippet to your executable script
You're prevented locally from committing to protected branches, i.e. master or develop. Open a Merge Request in GitLab instead.