10

Is there a way to set a specific branch on GitHub to pull-only (read-only) or can I only set this for the whole repository?

manojlds
  • 275,671
  • 58
  • 453
  • 409
znq
  • 43,855
  • 39
  • 115
  • 144

3 Answers3

17

You actually can (sort of), since September 2015.

That is because you now have "Protected branches and required status checks" (September 3, 2015), which allows you to protect a branch:

  • against forced pushed
  • against deletion
  • against merged changes until required status checks pass

As mentioned in the twitter discussion:

@github nice, what about protect from just push and allow only operating through pull requests?

Adam Roben ‏@aroben @lowl4tency You can do this via the Status API:
create a "success" status only on commits in PRs, then mark that status as required
.

https://cloud.githubusercontent.com/assets/25792/9596474/27db3ce6-502a-11e5-9b19-5b47a8addc65.png


Since Nov. 2015, you can protect a branch with the API:

curl "https://api.github.com/repos/github/hubot/branches/master" \
  -XPATCH \
  -H 'Authorization: token TOKEN'
  -H "Accept: application/vnd.github.loki-preview" \
  -d '{
    "protection": {
      "enabled": true,
      "required_status_checks": {
        "enforcement_level": "everyone",
        "contexts": [
          "required-status"
        ]
      }
    }
  }'

How can I try it?

To access this functionality during the preview period, you’ll need to provide the following custom media type in the Accept header:

application/vnd.github.loki-preview+json

Since March 2016, Organizations can now specify which members and teams are able to push to a protected branch.

https://cloud.githubusercontent.com/assets/4719/14140705/ed98abac-f67a-11e5-951e-b48c842fb77f.png

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
6

There is no way to do branch level permissions on Github, but the gitolite project supports what you're looking for.

brycemcd
  • 4,153
  • 3
  • 23
  • 29
  • 1
    well it's possible, but I can't speak to the roadmap of features Github intends to deploy. It's technically possible, but I don't know if Github intends to ever support it – brycemcd Sep 26 '11 at 09:27
  • since I posted this several years ago, @VonC's looks like it works for Github. Gitlab also supports protected branches. – brycemcd Nov 01 '16 at 19:00
1

Starting from March 30th 2016, GitHub does support branch permissions without any further tricks like required status checks: https://github.com/blog/2137-protected-branches-improvements