Skip to content

Respect repository default branch in gh stack link#265

Merged
skarim merged 2 commits into
mainfrom
copilot/fix-default-branch-respect
Jul 24, 2026
Merged

Respect repository default branch in gh stack link#265
skarim merged 2 commits into
mainfrom
copilot/fix-default-branch-respect

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

gh stack link hardcoded --base to main, so omitting the flag retargeted the bottom PR of the stack to main regardless of the repository's actual default branch. It now resolves the default branch dynamically, matching gh stack init.

Changes

  • cmd/link.go: --base now defaults to "". When unset, runLinkCreateOrUpdate resolves the bottom base via git.DefaultBranch() (the same path as init), erroring with Use --base to specify the base branch if it can't be determined. Add-mode is unaffected since it ignores --base by design.
  • cmd/link_test.go: Added git.SetOps mocks to existing PR-number/URL create-path tests (previously leaning on real git ops), plus focused tests for retargeting an existing bottom PR to the default branch, creating a bottom PR on it, the unresolvable-default error, and explicit --base bypassing resolution.
  • Docs (README.md, docs/reference/cli.md, skills/gh-stack/SKILL.md): updated the --base default description.

Behavior

# repo default branch is "develop"
gh stack link 10 20 30      # bottom PR now targets develop (was: main)
gh stack link --base main 10 20 30   # explicit base still honored

Copilot AI changed the title [WIP] Fix gh stack link to respect default branch of repository Respect repository default branch in gh stack link Jul 22, 2026
Copilot AI requested a review from skarim July 22, 2026 03:52
@skarim
skarim marked this pull request as ready for review July 23, 2026 22:34
Copilot AI review requested due to automatic review settings July 23, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates gh stack link to use the repository’s default branch when --base is omitted.

Changes:

  • Dynamically resolves the bottom PR’s base branch.
  • Adds regression tests for default, explicit, and unresolved bases.
  • Updates CLI documentation.
Show a summary per file
File Description
cmd/link.go Resolves the default base branch.
cmd/link_test.go Adds coverage and git mocks.
README.md Updates flag documentation.
docs/src/content/docs/reference/cli.md Updates CLI reference.
skills/gh-stack/SKILL.md Updates agent guidance.

Review details

  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Medium

@skarim

skarim commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Validated this is working correctly with non-standard default branch names

$ gh stack link branch1 branch2
Checking existing stacks...
Pushing 2 branches to origin...
Looking up PRs for 2 branches...
Creating 2 PRs...
✓ Created PR [#1](https://github.com/skarim/custombasebranchtest/pull/1) for branch1 (base: custombasebranch)
✓ Created PR [#2](https://github.com/skarim/custombasebranchtest/pull/2) for branch2 (base: branch1)
✓ Created stack with 2 PRs (stack #3)

@skarim
skarim merged commit 6dcf9f0 into main Jul 24, 2026
8 checks passed
@skarim
skarim deleted the copilot/fix-default-branch-respect branch July 24, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh stack link does not respect the default branch of a repository

4 participants