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?
-
2Are you asking if it's possible to disallow pushing on specific branches? – Paragon Sep 23 '11 at 14:54
-
See also http://stackoverflow.com/a/5097437/6309 – VonC Sep 20 '13 at 06:34
-
You can do this easily with bitbucket. – Malcolm Nov 13 '14 at 21:32
-
Note: this is now (Sept. 2015) possible with GitHub! See [my answer below](http://stackoverflow.com/a/32384255/6309). – VonC Sep 03 '15 at 19:48
-
Note: since March 2016, an organization can restrict push to certain team members. See [my edited answer below](http://stackoverflow.com/a/32384255/6309) – VonC Mar 30 '16 at 20:05
-
It's now (Oct 20th, 2022) supported officially. See: https://stackoverflow.com/a/74343915/1592410 – Johann Chang Nov 07 '22 at 08:47
5 Answers
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.
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.

- 1,262,500
- 529
- 4,410
- 5,250
There is no way to do branch level permissions on Github, but the gitolite project supports what you're looking for.

- 4,343
- 3
- 26
- 29
-
1well 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
-
Add the branch as a protected branch and then there is an option as : Lock Branch (Branch is read-only. Users cannot push to the branch.) – Sudheer Kumar Nov 21 '22 at 04:11
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

- 79
- 3
This request can now be done with the option Lock branch.
Reference: New Branch Protections: Last Pusher and Locked Branch
Lock branch
This allows for branches to be locked, prohibiting changes. You can lock a branch allowing you to have a maintenance window and prevent changes, or to protect a fork so it only receives changes from its upstream repository.
To use this feature in a branch protection rule, enable Lock branch.

- 1,281
- 2
- 14
- 25
Go to the Settings, Add the branch as a protected branch and then there is an option as : Lock Branch (Branch is read-only. Users cannot push to the branch.)

- 311
- 4
- 16