Skip to main content

Command referencegh repo fork

gh repo fork command (Linux & Windows / GitHub CLI)

Linux & WindowsGitHub CLIgitbeginner

What it does

Fork a GitHub repository to your account and optionally clone the fork locally. When people search for gh repo fork, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.

Fork a GitHub repository to your account and optionally clone the fork locally.

Syntax

gh repo fork [<repository>] [--clone] [--remote] [flags]

Common options

Flag / optionMeaning
--cloneClone the fork after creating it.
--remoteAdd a git remote for the fork.
--orgFork into an organization.
--default-branch-onlyCopy only the default branch when available.

Practical examples

Fork and clone

gh repo fork cli/cli --clone

Creates your fork and clones it in one step.

Fork current upstream

gh repo fork --remote

Forks the current repository’s upstream into your account.

Org fork

gh repo fork OWNER/REPO --org my-org

Places the fork under an organization you can access.

Common mistakes

  • Forking then pushing to origin when origin still points at the upstream you cannot write to.
  • Creating duplicate forks repeatedly instead of reusing the existing fork.

FAQ

What does gh repo fork do in GitHub CLI?

Fork a GitHub repository to your account and optionally clone the fork locally.

Does gh repo fork work on Windows and Linux?

Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.

What is a practical gh repo fork example?

Try `gh repo fork cli/cli --clone` — Creates your fork and clones it in one step.

Do I need a token in the command line for gh repo fork?

Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.