Skip to content

Respect repository default branch in gh stack link#265

Draft
skarim with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-default-branch-respect
Draft

Respect repository default branch in gh stack link#265
skarim with Copilot wants to merge 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
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

2 participants