【Github】Github の 各種設定 ~ 入門編 ~

■ はじめに

Github で設定について、少しづつだけどTipsを追加していく

目次

【0】Github の設定のキモ
【1】Pull-Request
 1)プルリク後にfeatureブランチを削除
【2】Branches
 1)ルール作成し、ブランチを保護する
【3】Tags
 1)使用上の注意
【4】Rulesets

【0】Github の設定のキモ

* 基本的には、以下の印象。
 この事をベースに自分のやりたいこと調べてみるのが良さそう。

[1] プルリクに関する設定(詳細は【1】参照)
[2] 以下のベースによる設定(設定内容は【1】参照)
 2-1) ブランチ
 2-2) タグ

【1】Pull-Request

Rules Explanations Default Memo
Allow merge commits マージコミット許容 Yes
Allow squash merging スカッシュマージ許容 Yes
Allow rebase merging リベースマージ許容 Yes
Always suggest updating pull request branches 常にプルリクブランチ更新の提案 No
Allow auto-merge オートマージ許容 No
Automatically delete head branches マージ後のブランチ元の自動削除 No

1)プルリク後にfeatureブランチを削除

手順

[1] Github の対象リポジトリにログインする
[2] [Settings]-[General]を選択
[3] 「Pull Requests」欄の「Automatically delete head branches」にチェックを付ける

【2】Branches

0)Branch protections

cf. Restrict = 制限
Rules Explanations Memo
Restrict creations 作成制限
Restrict updates 更新制限
Restrict deletions 削除制限
Require linear history 直線状の履歴を必須 マージコミット禁止。保護されたブランチについて - GitHub Docs
Require deployments to succeed デプロイ成功必須
Require signed commits コミット時、デジタル署名を必須 保護されたブランチについて - GitHub Docs
Require a pull request before merging マージする前に、プルリクエストを要求する
Require status checks to pass マージする前に、status checkをクリアしていることを要求する
Block force pushes force push禁止 保護されたブランチについて - GitHub Docs
Require code scanning results コード分析エンジン CodeQL を使用してスキャン

1)ルール作成し、ブランチを保護する

「【1】Pull-Request」で「1)プルリク後にfeatureブランチを削除」を設定した際に
消して欲しくないブランチ(例えば、Releaseブランチ)まで削除されてしまったので
特定ブランチを保護する設定を行う

手順

[1] Github の対象リポジトリにログインする
[2] [Settings]-[Branches]を選択
[3] 「Add classic branch protection rule」リンク押下
[4] 以下、入力し、「Create」ボタン押下
 * Branch name pattern: <保護するブランチ名>(e.g. develop)
 (「Allow deletions(削除を許可)」にチェックがないことを確認)

補足:Allow deletions(削除を許可)
https://docs.github.com/ja/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#allow-deletions

【3】Tags

1)使用上の注意

https://docs.github.com/ja/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/configuring-tag-protection-rules

より抜粋
~~~~~~~~~~~~
! Note
タグ保護ルールは 2024 年 8 月 30 日に非推奨になり、
ルールセットに置き換えられます。 
非推奨日以降も使用されているタグ保護ルールは自動的に移行されますが、
非推奨日より前に手動で移行することもできます。
~~~~~~~~~~~~

【4】Rulesets

* 以下の2通り。

[1] Branch ruleset
[2] Tag ruleset

[1] Branch ruleset

* 【1】参照

[2] Tag ruleset

* 基本できることは【1】と同じでTagベースになっただけ

参考文献

About Branch protection rules
https://zenn.dev/dzeyelid/articles/b8309a130d3b3b
https://qiita.com/fooramu/items/8601d07033d2c5e2f777

関連記事

Github ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/07/18/234652
Github ~ Merge / Squash / Rebase ~
https://dk521123.hatenablog.com/entry/2025/04/10/173912
Github の 各種設定 ~ Actions ~
https://dk521123.hatenablog.com/entry/2024/07/13/163010
Github Custom Action ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/06/27/220219
Github Actions ~ runs-onを動的変更することを考える ~
https://dk521123.hatenablog.com/entry/2024/05/18/032229