gh repo fork

Create a fork of a repository

Synopsis

Create a fork of a repository.

With no argument, creates a fork of the current repository. Otherwise, forks the specified repository.

By default, the new fork is set to be your 'origin' remote and any existing origin remote is renamed to 'upstream'. To alter this behavior, you can set a name for the new fork's remote with --remote-name.

Additional 'git clone' flags can be passed in by listing them after '--'.

gh repo fork [<repository>] [-- <gitflags>...] [flags]

Options

      --clone                Clone the fork {true|false}
      --remote               Add remote for fork {true|false}
      --remote-name string   Specify a name for a fork's new remote. (default "origin")

Options inherited from parent commands

      --help   Show help for command

In use

With no arguments

Inside a git repository, and without any arguments, we will automatically create a fork on GitHub on your account for your current directory. It will then prompt if you want to set an upstream remote.

# Create a fork for the current repository.
~/Projects/cli$ gh repo fork
- Forking cli/cli...
 Created fork user/cli
? Would you like to add a remote for the fork? Yes
 Renamed origin remote to upstream
 Added remote origin
~/Projects/cli$

With arguments

If you pass a repository in OWNER/REPO format, `gh` will automatically create a fork on GitHub on your account and ask if you want to clone it. This works inside or outside of a git repository.

# Create a fork for another repository.
~/Projects$ gh repo fork cli/cli
- Forking cli/cli...
 Created fork cli/cli
? Would you like to clone the fork? Yes
Cloning into 'cli'...
 Cloned fork
~/Projects$ cd cli
~/Projects/cli$

Using flags

Use flags to skip prompts about adding a git remote for the fork, or about cloning the forked repository locally.

# Skipping remote prompts using flags
~/Projects/cli$ gh repo fork --remote=false
- Forking cli/cli...
 Created fork user/cli
~/Projects/cli$
# Skipping clone prompts using flags
~/Projects$ gh repo fork cli/cli --clone=false
- Forking cli/cli...
 Created fork user/cli
~/Projects$