設定方法
対象のリモートリポジトリにアクセスし、Settings
のBranches
を選択します。
Branch name pattern
に対象ブランチの名前を入力しProtect matching branches
およびRules applied to everyone including administrators
から適用するルールを選択します。
選択後Create
をクリックします。
設定例
以下のように設定することでmain
ブランチへの直push
を禁止できます。
main
ブランチに直接push
しようとすると以下のようなエラーが出ます。
ターミナル
$ git push origin main
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 659 bytes | 659.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: At least 1 approving review is required by reviewers with write access.
To github.com:GitHubUser/sample-app.git
! [remote rejected] main -> main (protected branch hook declined)
error: failed to push some refs to 'github.com:GitHubUser/sample-app.git'