Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

git - Can I specify a specific branch on GitHub pull-only (read-only)?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...