ブランチ保護ルールについて
リポジトリ内のブランチ保護ルールは、特定のブランチ、あるいはすべてのブランチやfnmatch
構文で指定した名前のパターンにマッチするブランチに対して作成できます。 たとえば、release
という語を含む任意のブランチを保護するには、ブランチルールを*release*
に対して作成できます。
ワイルドカード構文 *
で、リポジトリ内の現在および将来のブランチすべてに対するルールを作成できます。 GitHubは、File.fnmatch
構文に File::FNM_PATHNAME
フラグを使用するので、ワイルドカードはディレクトリの区切り文字 (/
) には一致しません。 たとえば、qa/*
は、qa/
で始まり、1 つのスラッシュが含まれるすべてのブランチにマッチします。 qa/**/*
とすると、複数のスラッシュにマッチします。また、より多くのブランチにマッチさせるため、qa
の文字列を qa**/**/*
とすることもできます。 ブランチのルールに関する構文オプションの詳しい情報については、 fnmatch ドキュメンテーションを参照してください。
リポジトリが同じブランチに影響する複数の保護されたブランチのルールを持っているなら、特定のブランチ名を含むルールがもっとも高い優先順位を持ちます。 同じ特定のブランチ名を参照する保護されたブランチのルールが複数あるなら、最初に作成されたブランチルールが高い優先順位を持ちます。
*
、?
、]
などの特殊文字を含む保護されたブランチのルールは、作成された順序で適用されるので、これらの文字を持つ古いルールが高い優先順位を持ちます。
既存のブランチのルールに例外を作成するため、特定のブランチ名に対するルールなど、優先度の高いブランチ保護ルールを新しく作成できます。
For more information about each of the available branch protection settings, see "About protected branches."
ブランチ保護ルールを作成する
ブランチのルールを作成する際に、指定したブランチがリポジトリにしている必要はありません。
-
GitHub.comで、リポジトリのメインページにアクセスしてください。
-
リポジトリ名の下で Settings(設定)をクリックしてください。
-
In the "Code and automation" section of the sidebar, click Branches.
-
"Branch protection rules(ブランチ保護のルール)"の隣のAdd rule.(ルールの追加)をクリックしてください。
-
"Branch name pattern(ブランチ名のパターン)"の下で、保護したいブランチの名前もしくはパターンを入力してください。
-
Optionally, enable required pull requests.
-
Under "Protect matching branches", select Require a pull request before merging.
-
Optionally, to require approvals before a pull request can be merged, select Require approvals, click the Required number of approvals before merging drop-down menu, then select the number of approving reviews you would like to require on the branch.
-
コードを変更するコミットがブランチにプッシュされたときにプルリクエストの承認レビューを却下する場合は、[Dismiss stale pull request approvals when new commits are pushed] を選択します。
-
指定されたオーナーのコードにプルリクエストが影響する場合に、コードオーナーからのレビューを必須にする場合は、[Require review from Code Owners] を選択します。 詳細は「コードオーナーについて」を参照してください。
-
Optionally, to allow specific actors to push code to the branch without creating pull requests when they're required, select Allow specified actors to bypass required pull requests. Then, search for and select the actors who should be allowed to skip creating a pull request.
-
リポジトリが Organization の一部である場合、[Restrict who can dismiss pull request reviews] を選択します。 Then, search for and select the actors who are allowed to dismiss pull request reviews. 詳しい情報についてはプルリクエストレビューの却下を参照してください。
-
-
必要に応じて、ステータスチェック必須を有効化します。 詳しい情報についてはステータスチェックについてを参照してください。
- [Require status checks to pass before merging] を選択します。
- プルリクエストを保護されたブランチの最新コードで確実にテストしたい場合は、[Require branches to be up to date before merging] を選択します。
- Search for status checks, selecting the checks you want to require.
- [Require status checks to pass before merging] を選択します。
-
必要に応じて、[Require signed commits] を選択します。
-
必要に応じて、[Require linear history] を選択します。
-
Optionally, to merge pull requests using a merge queue, select Require merge queue. For information about merge queue, see "Managing a merge queue."
Tip: The pull request merge queue feature is currently in limited public beta and subject to change. Organizations owners can request early access to the beta by joining the waitlist.
-
Optionally, to choose which environments the changes must be successfully deployed to before merging, select Require deployments to succeed before merging, then select the environments.
-
Optionally, select Apply the rules above to administrators.
-
必要に応じて、GitHub Team または GitHub Enterprise Cloud を使用する Organization がリポジトリを所有している場合には、ブランチ制限を有効化します。
- [Restrict who can push to matching branches] を選択します。
- Optionally, to also restrict the creation of matching branches, select Restrict pushes that create matching branches.
- Search for and select the people, teams, or apps who will have permission to push to the protected branch or create a matching branch.
- [Restrict who can push to matching branches] を選択します。
-
必要に応じて、[Rules applied to everyone including administrators] で [Allow force pushes] を選択します。
Then, choose who can force push to the branch.
-
Select Everyone to allow everyone with at least write permissions to the repository to force push to the branch, including those with admin permissions.
-
Select Specify who can force push to allow only specific actors to force push to the branch. Then, search for and select those actors.
For more information about force pushes, see "Allow force pushes."
-
-
必要に応じて、[Allow deletions] を選択します。
-
Create(作成)をクリックしてください。
ブランチ保護ルールを編集する
-
GitHub.comで、リポジトリのメインページにアクセスしてください。
-
リポジトリ名の下で Settings(設定)をクリックしてください。
-
In the "Code and automation" section of the sidebar, click Branches.
-
編集する保護ルールの右にある [Edit] をクリックします。
-
ブランチ保護ルールを自由に変更してください。
-
[Save changes] をクリックします。
ブランチ保護ルールを削除する
-
GitHub.comで、リポジトリのメインページにアクセスしてください。
-
リポジトリ名の下で Settings(設定)をクリックしてください。
-
In the "Code and automation" section of the sidebar, click Branches.
-
削除する保護ルールの右にある [Delete] をクリックします。