gh repo fork
gh repo fork [<repository>] [-- <gitflags>...] [flags]
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
The "upstream" remote will be set as the default remote repository.
Additional git clone flags can be passed after
- Clone the fork
- Only include the default branch in the fork
- Rename the forked repository
- Create the fork in an organization
- Add a git remote for the fork
- Specify the name for the new remote
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$
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$
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$