Skip to content

Add --no-upstream flag to repo clone#12686

Open
4RH1T3CT0R7 wants to merge 1 commit intocli:trunkfrom
4RH1T3CT0R7:add-no-upstream-flag
Open

Add --no-upstream flag to repo clone#12686
4RH1T3CT0R7 wants to merge 1 commit intocli:trunkfrom
4RH1T3CT0R7:add-no-upstream-flag

Conversation

@4RH1T3CT0R7
Copy link

@4RH1T3CT0R7 4RH1T3CT0R7 commented Feb 14, 2026

Summary

Closes #8274

When cloning a forked repository, gh repo clone automatically adds the parent repo as an upstream remote and sets it as the default repository. This can be problematic when:

  • The user lacks access to the parent repo (causing confusing permission errors)
  • The upstream fetch is expensive for large repos
  • The user simply doesn't want the upstream remote

This PR adds a --no-upstream flag that skips adding the upstream remote when cloning a fork.

Behavior

Scenario SetRemoteResolution
--no-upstream + fork origin set as base (the fork becomes the default repo)
no flag + fork upstream set as base (existing behavior, unchanged)
not a fork no SetRemoteResolution call (existing behavior, unchanged)
  • --no-upstream is mutually exclusive with --upstream-remote-name (enforced via cobra.MarkFlagsMutuallyExclusive)
  • For non-fork repos, --no-upstream is a harmless no-op

Changes

  • pkg/cmd/repo/clone/clone.go: Add NoUpstream field, register --no-upstream flag, update fork handling logic, update help text and examples
  • pkg/cmd/repo/clone/clone_test.go: Add flag parsing tests, mutual exclusion test, integration tests for fork/non-fork with --no-upstream

Test plan

  • go test ./pkg/cmd/repo/clone/... - all tests pass
  • go vet ./pkg/cmd/repo/clone/... - no issues
  • go build ./cmd/gh - builds successfully
  • Manual: gh repo clone <fork> --no-upstream clones without adding upstream remote
  • Manual: gh repo clone <fork> --no-upstream --upstream-remote-name test errors with mutual exclusion message
  • Manual: gh repo clone <non-fork> --no-upstream clones normally (no-op)

When cloning a forked repository, `gh repo clone` automatically adds the
parent repo as an `upstream` remote and sets it as the default repository.
This can be problematic when the user lacks access to the parent repo,
the upstream fetch is expensive for large repos, or the user simply
doesn't want the upstream remote.

Add a `--no-upstream` flag that skips adding the upstream remote when
cloning a fork. When used, origin (the fork) is set as the default
repository instead. The flag is mutually exclusive with
`--upstream-remote-name`. For non-fork repos the flag is a harmless
no-op.

Closes cli#8274
Copilot AI review requested due to automatic review settings February 14, 2026 17:31
@4RH1T3CT0R7 4RH1T3CT0R7 requested a review from a team as a code owner February 14, 2026 17:31
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 14, 2026
Copy link
Contributor

Copilot AI left a comment

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 adds a --no-upstream flag to gh repo clone to address issue #8274. When cloning a forked repository, the current behavior automatically adds the parent repository as an upstream remote, which can cause permission errors or expensive fetches when the user lacks access to or doesn't need the parent repo. The new flag allows users to skip adding the upstream remote entirely, with the fork itself becoming the default repository.

Changes:

  • Added --no-upstream boolean flag that is mutually exclusive with --upstream-remote-name
  • Modified fork handling logic to conditionally set origin as the base remote when --no-upstream is true
  • Added comprehensive tests for flag parsing, mutual exclusion, and integration scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/cmd/repo/clone/clone.go Adds NoUpstream field to CloneOptions, registers the flag with mutual exclusivity constraint, updates fork handling to conditionally skip upstream remote setup, and adds documentation
pkg/cmd/repo/clone/clone_test.go Adds unit tests for flag parsing, mutual exclusion validation, and integration tests for both fork and non-fork scenarios with --no-upstream

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh repo clone without upstream

2 participants