cache selected remote#128
Open
skarim wants to merge 2 commits into
Open
Conversation
Users with multiple git remotes are prompted to choose a remote on every gh stack operation, which is tedious. This adds the ability to persist that choice so it only needs to be made once. When a user interactively selects a remote (because multiple remotes exist and none is configured as a push default), they are now shown a Y/n follow-up prompt offering to save that remote for all future gh stack operations. If accepted, the choice is written to the local git config key `gh-stack.remote`, and instructions for changing or clearing it are printed. The saved remote is checked in `ResolveRemote` after the standard git push config keys (branch.<name>.pushRemote, remote.pushDefault, branch.<name>.remote) but before falling back to listing all remotes. This means per-branch git push configuration still takes precedence, and the --remote flag on individual commands continues to override everything. All commands that resolve a remote (push, submit, sync, rebase, checkout, link, modify, trunk) go through the shared `pickRemote` helper, so they all benefit automatically. Changes: - Add GetSavedRemote, SaveRemote, ClearRemote to the git Ops interface, defaultOps implementation, public wrappers, and MockOps - Check gh-stack.remote in ResolveRemote's priority chain - Move pickRemote from push.go to utils.go as a shared helper - Add save-remote confirmation prompt after interactive remote selection - Add unit tests for pickRemote save/decline/skip/override flows - Add integration tests for ResolveRemote with saved remote and precedence, and for the SaveRemote/GetSavedRemote/ClearRemote lifecycle
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds persistence for the user's remote selection in gh-stack. When a user with multiple git remotes interactively selects a remote, they are now offered a follow-up prompt to save that choice to the gh-stack.remote git config key, so they won't be re-prompted on every operation.
Changes:
- Added
GetSavedRemote,SaveRemote,ClearRemoteto the gitOpsinterface, with corresponding implementations, wrappers, and mock methods - Integrated the saved remote check into
ResolveRemote's priority chain (after standard git push config, before falling back to remote listing) - Moved
pickRemotefrompush.gotoutils.goas a shared helper and extended it with a confirm-to-save prompt after interactive selection
Show a summary per file
| File | Description |
|---|---|
| internal/git/gitops.go | Adds GetSavedRemote/SaveRemote/ClearRemote implementations and integrates saved remote into ResolveRemote |
| internal/git/git.go | Adds public wrapper functions for the three new Ops methods |
| internal/git/mock_ops.go | Adds mock fields and method stubs for the new interface methods |
| cmd/utils.go | Moves pickRemote here from push.go, adds confirmSaveRemote helper with save-on-confirm flow |
| cmd/push.go | Removes old pickRemote and cleans up unused imports |
| internal/git/gitops_test.go | Adds integration tests for saved remote resolution and lifecycle |
| cmd/push_test.go | Adds unit tests for the new pickRemote save/skip/override behaviors |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ktravers
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Save selected remote to
gh-stack.remotegit configUsers with multiple git remotes are prompted to choose a remote on every
gh stackoperation, which is tedious. This adds the ability to persist that choice so it only needs to be made once.Behavior
When a user interactively selects a remote (because multiple remotes exist and none is configured as a push default), they are now shown a Y/n follow-up prompt offering to save that remote for all future gh stack operations. If accepted, the choice is written to the local git config key
gh-stack.remote, and instructions for changing or clearing it are printed:The saved remote is checked in
ResolveRemoteafter the standard git push config keys (branch.<name>.pushRemote,remote.pushDefault,branch.<name>.remote) but before falling back to listing all remotes. This means per-branch git push configuration still takes precedence, and the--remoteflag on individual commands continues to override everything.All commands that resolve a remote (push, submit, sync, rebase, checkout, link, modify, trunk) go through the shared
pickRemotehelper, so they all benefit automatically.Changes
internal/git/gitops.go:
GetSavedRemote,SaveRemote,ClearRemotemethods toOpsinterface anddefaultOpsgh-stack.remoteinResolveRemotepriority chain (after standard git push config, before remote listing)internal/git/git.go:
GetSavedRemote,SaveRemote,ClearRemoteinternal/git/mock_ops.go:
Opsmethodscmd/utils.go:
pickRemotehere frompush.goas a shared helperconfirmSaveRemotehelper for the Y/n save promptcmd/push.go:
pickRemote(moved toutils.go), clean up unused importsinternal/git/gitops_test.go:
ResolveRemoteuses saved remote, git push config takes precedence over saved remote,SaveRemote/GetSavedRemote/ClearRemotelifecyclecmd/push_test.go:
pickRemotesaves when confirmed, skips save when declined, skips prompt for single remote, override takes precedence