Command referencegh repo fork
gh repo fork command (Linux & Windows / GitHub CLI)
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 / option | Meaning |
|---|---|
| --clone | Clone the fork after creating it. |
| --remote | Add a git remote for the fork. |
| --org | Fork into an organization. |
| --default-branch-only | Copy 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.
Related commands
- gh repo cloneClone a GitHub repository to your machine using your authenticated gh settings.
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- gh repo syncSync the local repository or a fork branch with its upstream default branch.
- gh repo viewDisplay metadata about a GitHub repository in the terminal or open it in a browser.
- gh auth loginAuthenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
- gh pr mergeMerge a pull request using merge commit, squash, or rebase strategies.
- gitTrack source history and collaborate through distributed repositories.
- gh pr checkoutCheck out a pull request locally as a branch so you can build, test, or review the changes.
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.