gh repo fork
Fork and set up remotes in one step
gh repo fork creates your own copy of a repository and, optionally, clones it and configures the remotes — origin pointing at your fork and upstream at the original. It's the fastest way to start contributing to a project.
gh repo fork cli/cli --cloneSyntax
gh repo fork [<repository>] [-- <git-clone-flags>] [flags]Examples
Fork a repo and clone it locally
gh repo fork cli/cli --cloneFork the repo you're already inside
gh repo forkFork into an organization
gh repo fork cli/cli --org my-team --cloneFork with a custom name
gh repo fork cli/cli --fork-name my-cli --cloneOptions & flags
| Flag | What it does |
|---|---|
| --clone | Clone the new fork after creating it. |
| --remote | Add a git remote for the fork in the current repo. |
| --remote-name | Name for the fork remote (default "origin"). |
| --org | Create the fork in the given organization. |
| --fork-name | Rename the forked repository. |
| --default-branch-only | Only include the default branch in the fork. |
How to use gh repo fork, step by step
- Run
gh repo fork owner/name --clone. - gh creates the fork under your account and clones it.
- It sets
originto your fork andupstreamto the original. - Create a branch, commit, push, then open a PR with
gh pr create.
Common errors and fixes
already have a fork of owner/name
You already forked it. Just clone your fork with gh repo clone your-user/name, or run fork with --clone to reuse it.
failed to fork: HTTP 403
Forking may be disabled for this repository or organization, or your token lacks access. Check the repo settings and your auth scopes.
Related commands
Frequently asked questions
How do I fork a repository with GitHub CLI?
Run gh repo fork owner/name --clone. gh creates the fork on your account, clones it, and sets origin to your fork and upstream to the source repository.
Can I fork a repo into an organization?
Yes. Add --org: gh repo fork cli/cli --org my-team --clone creates the fork under that organization.
Does gh repo fork add the upstream remote?
When you clone the fork, gh configures upstream to point at the original repository so you can pull in new changes with git fetch upstream.