>_ ghcli.com
ghcli / Repositories / gh repo fork

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.

Quick answer
gh repo fork cli/cli --clone

Syntax

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

Examples

Fork a repo and clone it locally

gh repo fork cli/cli --clone

Fork the repo you're already inside

gh repo fork

Fork into an organization

gh repo fork cli/cli --org my-team --clone

Fork with a custom name

gh repo fork cli/cli --fork-name my-cli --clone

Options & flags

FlagWhat it does
--cloneClone the new fork after creating it.
--remoteAdd a git remote for the fork in the current repo.
--remote-nameName for the fork remote (default "origin").
--orgCreate the fork in the given organization.
--fork-nameRename the forked repository.
--default-branch-onlyOnly include the default branch in the fork.

How to use gh repo fork, step by step

  1. Run gh repo fork owner/name --clone.
  2. gh creates the fork under your account and clones it.
  3. It sets origin to your fork and upstream to the original.
  4. 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.