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 fi xing 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.

For more information on open source, specifically how to create and grow an open source project, we've createdOpen Source Guidesthat 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 freeGitHub Skillscourse on maintaining open source communities.

Prerequisites

If you haven't yet, first set up Git and authentication with GitHub 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 sameoctocat/Spoon-Kniferepository you just forked.

  1. On GitHub, navigate to theoctocat/Spoon-Kniferepository.

  2. In the top-right corner of the page, clickFork.

    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, selectCopy 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. ClickCreate fork.

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

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

To create a fork of a repository, use thegh repo forksubcommand.

gh repo fork REPOSITORY

To create the fork in an organization, use the--orgflag.

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

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

In GitHub Desktop, if you attempt to clone a repository that you don't have write access to, a fork is automatically created for you.

  1. In theFilemenu, clickClone 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 highlighted with an orange outline.
  2. Click the tab that corresponds to the location of the repository you want to clone. You can also clickURLto manually enter the repository location.

    Screenshot of the "Clone a repository" window. At the top of the window, tabs labeled "GitHub.com", "GitHub Enterprise" and "URL" are highlighted with an orange outline.
  3. From the list of repositories, click the repository you want to clone.

    Screenshot of the "Clone a repository" window. The "github/docs" repository 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, clickChoose...and navigate to the directory.

    Screenshot 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, clickClone.

  6. Read the information in the "How are you planning to use this fork?" window.

    • If you plan to use this fork for contributing to the original upstream repository, clickTo contribute to the parent project.
    • If you plan to use this fork for a project not connected to the upstream, clickFor my own purposes.
  7. ClickContinue.

Cloning your forked repository

Right now, you have a fork of the Spoon-Knife repository, but you do not have the files in that repository locally on your computer.

  1. On GitHub, navigate toyour forkof the Spoon-Knife repository.

  2. Above the list of files, clickCode.

    Screenshot of the list of files on the landing page of a repository. The "Code" button is highlighted with a dark orange outline.
  3. Copy the URL for the repository.

    • To clone the repository using HTTPS, under "HTTPS", click.

    • To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, clickSSH,then click.

    • To clone a repository using GitHub CLI, clickGitHub CLI,then click.

      Screenshot of the "Code" dropdown menu. To the right of the HTTPS URL for the repository, a copy icon is outlined in dark orange.
  4. OpenTerminalTerminalGit Bash.

  5. Change the current working directory to the location where you want the cloned directory.

  6. Typegit clone,and then paste the URL you copied earlier. It will look like this, with your GitHub username instead ofYOUR-USERNAME:

    git clone https://github /YOUR-USERNAME/Spoon-Knife
    
  7. PressEnter.Your local clone will be created.

    $gitclonehttps://github /YOUR-USERNAME/Spoon-Knife
    >Cloning into `Spoon-Knife`...
    >remote: Counting objects: 10,done.
    >remote: Compressing objects: 100% (8/8),done.
    >remote: Total 10 (delta 1), reused 10 (delta 1)
    >Unpacking objects: 100% (10/10),done.
    

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

To create a clone of your fork, use the--cloneflag.

gh repo fork REPOSITORY --clone=true
  1. In theFilemenu, clickClone 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 highlighted with an orange outline.
  2. Click the tab that corresponds to the location of the repository you want to clone. You can also clickURLto manually enter the repository location.

    Screenshot of the "Clone a repository" window. At the top of the window, tabs labeled "GitHub.com", "GitHub Enterprise" and "URL" are highlighted with an orange outline.
  3. From the list of repositories, click the repository you want to clone.

    Screenshot of the "Clone a repository" window. The "github/docs" repository 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, clickChoose...and navigate to the directory.

    Screenshot 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, clickClone.

Configuring Git to sync your fork with the upstream repository

When you fork a project in order to propose changes to the upstream repository, you can configure Git to pull changes from the upstream repository into the local clone of your fork.

  1. On GitHub, navigate to theoctocat/Spoon-Kniferepository.

  2. Above the list of files, clickCode.

    Screenshot of the list of files on the landing page of a repository. The "Code" button is highlighted with a dark orange outline.
  3. Copy the URL for the repository.

    • To clone the repository using HTTPS, under "HTTPS", click.

    • To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, clickSSH,then click.

    • To clone a repository using GitHub CLI, clickGitHub CLI,then click.

      Screenshot of the "Code" dropdown menu. To the right of the HTTPS URL for the repository, a copy icon is outlined in dark orange.
  4. OpenTerminalTerminalGit Bash.

  5. Change directories to the location of the fork you cloned.

    • To go to your home directory, type justcdwith no other text.
    • To list the files and folders in your current directory, typels.
    • To go into one of your listed directories, typecd YOUR-LISTED-DIRECTORY.
    • To go up one directory, typecd...
  6. Typegit remote -vand pressEnter.You will see the current configured remote repository for your fork.

    $git remote -v
    >origin https://github /YOUR-USERNAME/YOUR-FORK.git (fetch)
    >origin https://github /YOUR-USERNAME/YOUR-FORK.git (push)
    
  7. Typegit remote add upstream,and then paste the URL you copied in Step 3 and pressEnter.It will look like this:

    git remote add upstream https://github /ORIGINAL-OWNER/Spoon-Knife.git
    
  8. To verify the new upstream repository you have specified for your fork, typegit remote -vagain. You should see the URL for your fork asorigin,and the URL for the upstream repository asupstream.

    $git remote -v
    >origin https://github /YOUR-USERNAME/YOUR-FORK.git (fetch)
    >origin https://github /YOUR-USERNAME/YOUR-FORK.git (push)
    >upstream https://github /ORIGINAL-OWNER/ORIGINAL-REPOSITORY.git (fetch)
    >upstream https://github /ORIGINAL-OWNER/ORIGINAL-REPOSITORY.git (push)
    

Now, you can keep your fork synced with the upstream repository with a few Git commands. For more information, see "Syncing a fork."

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

To configure a remote repository for the forked repository, use the--remoteflag.

gh repo fork REPOSITORY --remote=true

To specify the remote repository's name, use the--remote-nameflag.

gh repo fork REPOSITORY --remote-name "main-remote-repo"

Editing a fork

You can make any changes to a fork, including:

  • Creating branches:Branchesallow you to build new features or test out ideas without putting your main project at risk.
  • Opening pull requests:If you want to contribute back to the upstream repository, you can send a request to the original author to pull your fork into their repository by submitting apull request.

Find another repository to fork

Fork a repository to start contributing to a project. You can fork any public repository to your personal account, or to an organization where you have permission to create repositories. If you have access to a private repository and the owner permits forking, you can fork the repository to your personal account, or to an organization on GitHub Team where you have permission to create repositories. You cannot fork a private repository to an organization using GitHub Free. For more information about GitHub Team and GitHub Free, see "GitHub’s plans." For more information about when you can fork a repository, see"About permissions and visibility of forks."

You can browseExplore GitHubto find projects and start contributing to open source repositories. For more information, see "Finding ways to contribute to open source on GitHub."

Next steps

You have now forked a repository, practiced cloning your fork, and configured an upstream repository.

  • For more information about cloning the fork and syncing the changes in a forked repository from your computer, see "Set up Git."

  • You can also create a new repository where you can put all your projects and share the code on GitHub. Creating a repository for your project allows you to store code in GitHub. This provides a backup of your work that you can choose to share with other developers. For more information, see "Quickstart for repositories."

  • Each repository on GitHub is owned by a person or an organization. You can interact with the people, repositories, and organizations by connecting and following them on GitHub. For more information, see "Finding inspiration on GitHub."

  • GitHub has a great support community where you can ask for help and talk to people from around the world. Join the conversation onGitHub Community.