1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】コマンドで保護ブランチを設定する方法

Posted at

コマンドで保護ブランチを設定する

以下を実行するとコマンドで保護ブランチを設定できます。

OWNER_NAMEREPO_NAMEは適宜変更が必要です。

protect-branch.sh
owner="OWNER_NAME"
repo="REPO_NAME"
repositoryId="$(gh api graphql -f query='{repository(owner:"'$owner'",name:"'$repo'"){id}}' -q .data.repository.id)"

gh api graphql -f query='
mutation($repositoryId:ID!,$branch:String!,$requiredReviews:Int!) {
  createBranchProtectionRule(input: {
    repositoryId: $repositoryId
    pattern: $branch
    requiresApprovingReviews: true
    requiredApprovingReviewCount: $requiredReviews
    isAdminEnforced: true
  }) { clientMutationId }
}' -f repositoryId="$repositoryId" -f branch="main" -F requiredReviews=1

実行後は以下のように設定されmainブランチには直接pushできなくなります。

image221019_204133.png

上記以外の設定をしたい場合には以下のページを参照して設定を追加します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?