Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent direct commits on master branch in git repository and accept merges only?

Tags:

git

merge

commit

My git repository has two branches, 'master' and 'dev'.

Code committed to 'dev' goes through an automated build process before it is tested. Code that passes this is then merged into the 'master' branch.

Is it possible, using hooks or something else, to prevent normal direct commits on the 'master' branch and only accept merges from 'dev' to 'master'?

like image 253
alexbilbie Avatar asked Aug 13 '11 19:08

alexbilbie


People also ask

How do I restrict direct push to master?

To find it go to Settings > Branches > Branch Protection Rules and click 'Add Rule'. Then, enter the name of the branch you want to protect and click the checkbox to require pull request reviews before merging.


1 Answers

Not a direct answer: consider using repos instead of branches for this. Imagine three repos: local, dev, and blessed. Local = your own repo where you work. Dev = the repo you push all your commits to and the one that your build process is monitoring for changes. Blessed = the repo that only the build process can push to and which you pull from. Thus you commit into local and push changes to dev. Auto-build does all it's testing of the commits you pushed and on success, pushes them to blessed. Then you (or anyone else) can pick them up from blessed and continue work from there.

like image 109
Ryan Stewart Avatar answered Oct 06 '22 08:10

Ryan Stewart