Skip to content

fix(repo fork): set default repo when adding fork remote - #12813

Closed
scarf005 wants to merge 2 commits into
cli:trunkfrom
scarf005:fix/3724/repo-fork-default-push-remote
Closed

scarf005 wants to merge 2 commits into
cli:trunkfrom
scarf005:fix/3724/repo-fork-default-push-remote

Conversation

@scarf005

@scarf005 scarf005 commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep the existing-clone remote-add behavior, but make default-repository updates explicit by prompting before setting remote..gh-resolved=base.
  • Add --yes to skip that confirmation in automation/non-interactive usage.
  • Update repo fork tests for prompt, non-interactive skip, and --yes opt-in paths.

Fixes #12833

Copilot AI review requested due to automatic review settings March 1, 2026 16:20
@scarf005
scarf005 requested a review from a team as a code owner March 1, 2026 16:20
@scarf005
scarf005 requested a review from BagToad March 1, 2026 16:20
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels Mar 1, 2026
@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:

  • None of the referenced issues have the help-wanted label

Please update your PR to address the above. Requirements:

  1. Include a detailed description of what this PR does
  2. Link to an issue with the help-wanted label (use Fixes #123 or Closes #123 if it resolves the issue)

This PR will be automatically closed in 7 days if these requirements are not met.

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

This PR updates gh repo fork behavior when run inside an existing local clone so that, when adding a fork remote, the original/parent repo remote (e.g., origin or renamed upstream) is marked as the directory’s default (“base”) repository for gh context resolution, and the TTY UX mirrors the clone-path messaging.

Changes:

  • Set remote.<parent>.gh-resolved=base when adding a fork remote in an existing clone (including after origin→upstream rename).
  • Print the “default repository set” message in TTY mode for this existing-clone remote-add path.
  • Update/extend repo fork tests to assert the new git config call and updated stderr output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/cmd/repo/fork/fork.go Tracks the parent remote name, updates it on rename, sets gh-resolved base, and prints the default-repo message in TTY.
pkg/cmd/repo/fork/fork_test.go Updates command stubs and expected output to cover the new gh-resolved base config and TTY messaging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cmd/repo/fork/fork.go Resolved
When forking from an existing clone with --remote, gh now marks the parent remote as the base repository automatically. This mirrors clone behavior so users can run repo commands immediately without a separate repo set-default step.

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Assisted-by: openai/gpt-5.3-codex on opencode
@scarf005
scarf005 force-pushed the fix/3724/repo-fork-default-push-remote branch from 95e811c to 4d4413b Compare March 1, 2026 16:27
@BagToad

BagToad commented Mar 2, 2026 •

Copy link
Copy Markdown
Member

Hi @scarf005, thank you for this. I'm a little confused though — I don't think this closes #3724 as linked. That issue is about git push failing because the default push remote isn't set, which this PR doesn't address. The gh-resolved base config helps gh commands (like gh pr create) know the base repo, but git push would still fail after this change.

I think aligning with the clone path makes mostly sense, but I'd like to understand where the motivation comes from — like what pain you're seeing — before changing this behavior, since one could argue it's a sort of breaking change for users who have existing expectations around the current fork-in-existing-repo behavior.

@scarf005

scarf005 commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

I think aligning with the clone path makes mostly sense, but I'd like to understand where the motivation comes from — like what pain you're seeing

to summarize: i've cloned a repo, then decided to fork it, but even after gh repo fork, i had to explicitly gh repo set-default to be able to push branches to origin. this felt counterintuitive.

on other thoughts, i think i've linked the PR to less relevant issue; will try updating the PR this weekends.

Ask for confirmation before writing gh-resolved base in existing-clone fork flows, and add --yes for explicit non-interactive opt-in. This addresses reviewer concerns about implicit behavior changes while preserving automation support.

Assisted-by: openai/gpt-5.3-codex on opencode
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team unmet-requirements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh repo fork: confirm before setting default repository in existing clones

3 participants