Skip to main content

Fork a repository

A fork is a new repository that shares code and visibility settings with the original “upstream” repository.

Platform navigation

About forks

A fork is a new repository that shares code and visibility settings with the original “upstream” repository. Forks are often used to iterate on ideas or changes before they are proposed back to the upstream repository, such as in open source projects or when a user does not have write access to the upstream repository. For more information, see Working with forks.

Propose changes to someone else's project

For example, you can use forks to propose changes related to fixing a bug. Rather than logging an issue for a bug you have found, you can:

  • Fork the repository.
  • Make the fix.
  • Submit a pull request to the project owner.

Use someone else's project as a starting point for your own idea.

Open source software is based on the idea that by sharing code, we can make better, more reliable software. For more information, see the About the Open Source Initiative on the Open Source Initiative.

For more information about applying open source principles to your organization's development work on GitHub, see GitHub's white paper An introduction to innersource.

When creating your public repository from a fork of someone's project, make sure to include a license file that determines how you want your project to be shared with others. For more information, see Choose an open source license at choosealicense.com.

For more information on open source, specifically how to create and grow an open source project, we've created Open Source Guides that will help you foster a healthy open source community by recommending best practices for creating and maintaining repositories for your open source project. You can also take a free GitHub Skills course on maintaining open source communities.

Prerequisites

If you haven't yet, first set up Git and authentication with GitHub.com from Git. For more information, see Set up Git.

Forking a repository

You might fork a project to propose changes to the upstream repository. In this case, it's good practice to regularly sync your fork with the upstream repository. To do this, you'll need to use Git on the command line. You can practice setting the upstream repository using the same octocat/Spoon-Knife repository you just forked.

  1. On GitHub, navigate to the octocat/Spoon-Knife repository.

  2. In the top-right corner of the page, click Fork.

    Screenshot of the main page of repository. A button, labeled with a fork icon and "Fork 59.3k," is outlined in dark orange.

  3. Under "Owner," select the dropdown menu and click an owner for the forked repository.

  4. By default, forks are named the same as their upstream repositories. Optionally, to further distinguish your fork, in the "Repository name" field, type a name.

  5. Optionally, in the "Description" field, type a description of your fork.

  6. Optionally, select Copy the DEFAULT branch only.

    For many forking scenarios, such as contributing to open-source projects, you only need to copy the default branch. If you do not select this option, all branches will be copied into the new fork.

  7. Click Create fork.

Note

If you want to copy additional branches from the upstream repository, you can do so from the Branches page. For more information, see Creating and deleting branches within your repository.

Note

To learn more about GitHub CLI, see About GitHub CLI.

To create a fork of a repository, use the gh repo fork subcommand.

gh repo fork REPOSITORY

To create the fork in an organization, use the --org flag.

gh repo fork REPOSITORY --org "octo-org"

You can fork a repository on GitHub.com or in GitHub Desktop. For information about forking on GitHub.com, see the web browser version of this article.

In GitHub Desktop, if you clone a repository that you do not have write access to, and then attempt to push a change to the repository, a fork will be created for you.

  1. In the File menu, click Clone Repository.

    Screenshot of the menu bar on a Mac. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

    Screenshot of the "GitHub Desktop" menu bar on Windows. The "File" dropdown menu is expanded, and the "Clone Repository" option is outlined in orange.

  2. Click the tab that corresponds to the location of the repository you want to clone. In this example, we click on the URL tab.

    Screenshot of the "URL" tab of the "Clone a repository" window. The "GitHub.com", "GitHub Enterprise" and "URL" tabs are outlined in dark orange.

  3. Enter the url or path of the repository you want to clone.

    Screenshot of the "URL" tab of the "Clone a repository" window. The input containing "octocat/Spoon-Knife" is highlighted with an orange outline.

  4. To select the local directory into which you want to clone the repository, next to the "Local Path" field, click Choose... and navigate to the directory.

    Screenshot of the "URL" tab of the "Clone a repository" window. A button, labeled "Choose", is highlighted with an orange outline.

  5. At the bottom of the "Clone a Repository" window, click Clone.

  6. To create a fork, attempt to push a change to the repository. For example, create a new branch and publish it. A prompt will appear asking if you want to fork this repository.