Open
Conversation
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
Contributor
There was a problem hiding this comment.
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-upstreamboolean flag that is mutually exclusive with--upstream-remote-name - Modified fork handling logic to conditionally set
originas the base remote when--no-upstreamis 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.
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.
Summary
Closes #8274
When cloning a forked repository,
gh repo cloneautomatically adds the parent repo as anupstreamremote and sets it as the default repository. This can be problematic when:This PR adds a
--no-upstreamflag that skips adding the upstream remote when cloning a fork.Behavior
SetRemoteResolution--no-upstream+ forkoriginset asbase(the fork becomes the default repo)upstreamset asbase(existing behavior, unchanged)SetRemoteResolutioncall (existing behavior, unchanged)--no-upstreamis mutually exclusive with--upstream-remote-name(enforced viacobra.MarkFlagsMutuallyExclusive)--no-upstreamis a harmless no-opChanges
pkg/cmd/repo/clone/clone.go: AddNoUpstreamfield, register--no-upstreamflag, update fork handling logic, update help text and examplespkg/cmd/repo/clone/clone_test.go: Add flag parsing tests, mutual exclusion test, integration tests for fork/non-fork with--no-upstreamTest plan
go test ./pkg/cmd/repo/clone/...- all tests passgo vet ./pkg/cmd/repo/clone/...- no issuesgo build ./cmd/gh- builds successfullygh repo clone <fork> --no-upstreamclones without adding upstream remotegh repo clone <fork> --no-upstream --upstream-remote-name testerrors with mutual exclusion messagegh repo clone <non-fork> --no-upstreamclones normally (no-op)