Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Prevent commits in master branch

(For simplicity) I have a master branch and a dev in my Git repository. I want to ensure the master branch is always working, so all work I do should be in the dev branch.

However, when I merge my changes in with a --no-ff merge, I tend to stay in the master branch, and just continue working in it (because I forget to checkout my dev branch).

Can I put up a rule for the master branch, which states I can't do commits, and fast-forward merges, but only --no-ff merges from another branch?

This must work for private hosted repositories (ergo, not GitHub or Bitbucket).

Answer*

Cancel
6
  • 1
    What if I have multiple repositories - won't it affect all of them? Commented Nov 5, 2019 at 12:32
  • 3
    and that is what you may what to do in most of the cases Commented Nov 8, 2019 at 11:24
  • Say I have this weird project, where they renamed master to Production - can exceptions be made? Commented Nov 8, 2019 at 15:21
  • 1
    Install what globally? Can you make it clearer in your answer? (But without "Edit:", "Update:", or similar - the answer should appear as if it was written today.) Commented Nov 24, 2021 at 21:24
  • 2
    @PeterMortensen I guess he meant to install the pre-commit hook globally for all local git repositories, since the .git folder lies inside each repo's folder. With the suggested action, there will be a global "githooks" folder, under user's home folder, where he/she can put the same pre-commit hook script and it will be active for commits to any repo. Commented Dec 14, 2021 at 2:46