Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent commits in a local branch

In my local git tree I pull commits from the "master" branch in the repository, but all development is done in a different branch, and pushed in a different branch too.

I would like to avoid mistakes and prevent accidental commits in my local "master" branch, and allow only pull requests (then I'd rebase the developement branch to the updated master). Is this possible? How?

like image 334
Jellby Avatar asked Jun 25 '13 09:06

Jellby


People also ask

Do you not commit to master?

Not committing to master prevents colliding commits and having to merge each time 2 people change the same file.


1 Answers

You can use a pre-commit hook.

For example, place the following script as .git/hooks/pre-commit:

#!/bin/bash
if test $(git rev-parse --abbrev-ref HEAD) = "master" ; then 
  echo "Cannot commit on master"
  exit 1
fi

And set it as executable

chmod +x .git/hooks/pre-commit
like image 108
brice Avatar answered Oct 04 '22 00:10

brice