5

We are a team of a few people. Everyone works on a feature branch and merges his stuff through GitHub UI into master when one is ready.

Now is it possible to prevent direct pushes to master, but instead create a pull request whenever a new feature is ready to be merged? Additionally it would be awsome to restrict merges to a subset of devs only.

Aley
  • 8,540
  • 7
  • 43
  • 56
  • 1
    The best way is to have a clear workflow. – Maroun Dec 07 '15 at 10:43
  • 1
    Look into [roles](https://help.github.com/articles/repository-permission-levels-for-an-organization/) in GitHub. Developers with read access can work on branches in their foked repositories and create PR's when their feature branch is ready to be merged. – houtanb Dec 07 '15 at 10:45
  • 1
    GitHub has a feature called [protected branches](https://help.github.com/articles/about-protected-branches). It won't take you all the way – for example it doesn't prevent anyone from committing directly to `master` – but at least it's a good start. – Enrico Campidoglio Dec 07 '15 at 11:26
  • @EnricoCampidoglio That unfortunately does not solve the problem, since its only for forced push. – Aley Dec 07 '15 at 14:27
  • @HBHB We have a private repo so one premium account. If one of my colleges clone the repo, it will be public, right? – Aley Dec 07 '15 at 14:27
  • 1
    @Aley no. If the repository is private your colleagues can fork it and their forked repositories will stay private. You just need to give them the rights to do so – houtanb Dec 07 '15 at 14:56

2 Answers2

2

Additionally it would be awsome to restrict merges to a subset of devs only.

You can restrict pushes to a branch in an Organization to specific users or teams. This will allow you to set up a team that can merge back into master.

branch restriction gif

Alternatively, for a small team, you can consider having each developer set up client-side hooks to prevent pushing to a remote master.

Lastly, if you use GitHub Enterprise that offers pre-receive hooks, you can enable one that enforces code to be merged through a PR

osowskit
  • 5,904
  • 2
  • 29
  • 38
0

go to settings tab click on Branches --> select Branch Protection Rules and here click Add Rules button, Branch name patterns = master

then tick below checkboxes

  1. Require pull request review before merging
  2. Require review from CODEOWNER file.

Note: -Add CODEOWNER file in your git top folder and inside it maintain Lead developers who can approve name like this * @apple @orange

You can read more on codeowner in below link https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

We haven't ticked include administrator option, Admin role account can do merge without review.

markalex
  • 8,623
  • 2
  • 7
  • 32