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?

【GitHub CLI】gh stackでスタックPRを管理する方法

1
Posted at

はじめに

gh stackを使用すると、複数のブランチとPull Requestを依存関係のあるスタックとして管理できます。

2026年8月時点ではパブリックプレビューのため、仕様が変更される可能性があります。

インストール

GitHub CLIをインストールして認証します。

brew install gh
gh auth login

続いて、gh stack拡張機能をインストールします。

gh extension install github/gh-stack

スタックを作成する

最初のブランチを作成します。

gh stack init feature-base

現在のブランチの上に、新しいブランチを追加します。

gh stack add feature-api
gh stack add feature-ui

スタックは次の順番になります。

main
└── feature-base
    └── feature-api
        └── feature-ui

Pull Requestを作成する

スタック内のブランチをPushし、Pull Requestをまとめて作成します。

gh stack submit

タイトルなどを自動生成する場合は、次のように実行します。

gh stack submit --auto

--autoでは新しいPull RequestがDraftとして作成されます。レビュー可能な状態で作成する場合は--openも指定します。

gh stack submit --auto --open

スタックを確認する

gh stack view

ブランチ名だけを表示する場合は次のとおりです。

gh stack view --short

ブランチを移動する

gh stack up
gh stack down
gh stack top
gh stack bottom
gh stack trunk

スタック内のブランチを選択する場合は、次のコマンドを使用します。

gh stack switch

最新状態に同期する

リモートの変更取得、リベース、Push、Pull Requestの同期をまとめて実行します。

gh stack sync

競合が発生した場合は、競合を解消してから次のコマンドを実行します。

git add .
gh stack rebase --continue

リベースを中止する場合は次のとおりです。

gh stack rebase --abort

スタックをマージする

現在のスタックを対話形式でマージします。

gh stack merge

確認を省略し、すべてSquash Mergeする場合は次のように実行します。

gh stack merge --yes --squash

基本的な流れ

通常は、次のコマンドを中心に使用します。

gh stack init feature-base
gh stack add feature-api
gh stack add feature-ui
gh stack submit
gh stack sync
gh stack merge

gh stackを利用すると、手作業で各Pull Requestのベースブランチを設定する必要がなくなり、依存する変更を小さなPull Requestに分割して管理できます。

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?