Skip to main content

Fork a repository

Fork a repository on GitHub to propose changes, collaborate on projects, and manage your own copy of the codebase.

Platform navigation

About forks

Forking a repository lets you propose changes to a project without affecting the upstream repository. See About forks.

Prerequisites

If you haven't already, set up Git and authentication with GitHub.com from Git. See Configurer Git.

Forking a repository

You might fork a project to propose changes to the upstream repository. In this case, it's good practice to sync your fork with the upstream repository regularly. 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, in the "Repository name" field, type a different name to distinguish your fork.

  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.

Remarque

If you want to copy additional branches from the upstream repository, you can do so from the Branches page. See Managing branches within your repository.

Remarque

Pour plus d’informations sur GitHub CLI, consultez À propos de l’interface CLI GitHub.

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.

Dans GitHub Desktop, si vous clonez un dépôt sur lequel vous n'avez pas d'accès en écriture, et que vous tentez ensuite d'y apporter une modification, une fourche sera créée pour vous.

  1. Dans le menu Fichier, cliquez sur Cloner le dépôt.

    Capture d’écran de la barre de menus sur un Mac. Le menu déroulant « Fichier » est développé et l’option « Cloner le dépôt » est mise en évidence avec un contour orange.

    Capture d'écran de la barre de menus « GitHub Desktop » sur Windows. Le menu déroulant « Fichier » est développé, et l’option « Cloner le référentiel » est mise en évidence en orange.

  2. Cliquez sur l’onglet qui correspond à l’emplacement du dépôt à cloner. Dans cet exemple, nous cliquons sur l'onglet URL.

    Capture d'écran de l'onglet « URL » de la fenêtre « Cloner un référentiel ». Les onglets « GitHub.com », « GitHub Enterprise » et « URL » sont mis en évidence en orange foncé.

  3. Entrez l'url ou le chemin du référentiel que vous souhaitez cloner.

    Capture d’écran de l’onglet « URL » de la fenêtre « Clôner un référentiel ». L’entrée contenant « octocat/Spoon-Knife » est mise en surbrillance avec un contour orange.

  4. Pour sélectionner le répertoire local dans lequel vous souhaitez cloner le dépôt, en regard du champ « Chemin d’accès local », cliquez sur Choisir... et accédez au répertoire.

    Capture d’écran de l’onglet « URL » de la fenêtre « Clôner un référentiel ». Un bouton, intitulé « Choisir », est mis en évidence avec un encadré orange.

  5. En bas de la fenêtre « Cloner un dépôt », cliquez sur Cloner.

  6. Pour créer une duplication, essayez d’envoyer une modification au référentiel. Par exemple, créer une nouvelle branche et la publier. Une invite s’affiche pour vous demander si vous souhaitez fourcher ce référentiel.

    Capture d'écran de la fenêtre « Créer une invite de fork ». Un bouton, intitulé « Mettre ce dépôt en duplication », est mis en évidence par un contour orange.

  7. Lisez les informations de la section « Comment envisagez-vous d’utiliser cette duplication ? » .

    • Si vous envisagez d’utiliser cette duplication pour contribuer au dépôt en amont d’origine, cliquez sur Pour contribuer au projet parent.
    • Si vous envisagez d’utiliser cette duplication pour un projet qui n’est pas connecté à l’amont, cliquez Pour mon propre usage.
  8. Cliquez sur Continuer.

Cloning your forked repository

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

  1. On GitHub, navigate to your fork of the Spoon-Knife repository.

  2. Au-dessus de la liste de fichiers, cliquez sur Code.

    Capture d’écran de la liste des fichiers dans la page d’accueil d’un dépôt. Le bouton « Code » est mis en évidence avec un encadré orange foncé.

  3. Copiez l’URL du dépôt.

    • Pour cloner le référentiel en utilisant HTTPS, sous « HTTPS », cliquez sur .

    • Pour cloner le dépôt avec une clé SSH, en incluant un certificat émis par l’autorité de certification SSH de votre organisation, cliquez sur SSH et sur .

    • Pour cloner un dépôt avec l’GitHub CLI, cliquez sur GitHub CLI et sur .

      Capture d’écran du menu déroulant « Code ». À droite de l’URL HTTPS du dépôt, une icône de copie est indiquée en orange foncé.

  4. Open your terminal or Git Bash.

  5. Remplacez le répertoire de travail actuel par l’emplacement où vous voulez mettre le répertoire cloné.

  6. Type git clone, then paste the URL you copied earlier. It will look like this, with your GitHub username instead of YOUR-USERNAME:

    git clone https://github.com/YOUR-USERNAME/Spoon-Knife
    
  7. Press Enter. Git creates your local clone.

    $ git clone https://github.com/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.
    

Cloning your forked repository

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

Remarque

Pour plus d’informations sur GitHub CLI, consultez À propos de l’interface CLI GitHub.

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

gh repo fork REPOSITORY --clone=true

Configuring Git to sync your fork with the upstream repository

When you fork a project 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 the octocat/Spoon-Knife repository.

  2. Au-dessus de la liste de fichiers, cliquez sur Code.

    Capture d’écran de la liste des fichiers dans la page d’accueil d’un dépôt. Le bouton « Code » est mis en évidence avec un encadré orange foncé.

  3. Copiez l’URL du dépôt.

    • Pour cloner le référentiel en utilisant HTTPS, sous « HTTPS », cliquez sur .

    • Pour cloner le dépôt avec une clé SSH, en incluant un certificat émis par l’autorité de certification SSH de votre organisation, cliquez sur SSH et sur .

    • Pour cloner un dépôt avec l’GitHub CLI, cliquez sur GitHub CLI et sur .

      Capture d’écran du menu déroulant « Code ». À droite de l’URL HTTPS du dépôt, une icône de copie est indiquée en orange foncé.

  4. Open your terminal or Git Bash.

  5. Change to the directory for the fork you cloned.

    • To go to your home directory, type just cd with no other text.
    • To list the files and folders in your current directory, type ls.
    • To go into one of your listed directories, type cd YOUR-LISTED-DIRECTORY.
    • To go up one directory, type cd ...
  6. Type git remote -v and press Enter. You will see the remote repository currently configured for your fork.

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

    git remote add upstream https://github.com/ORIGINAL-OWNER/Spoon-Knife.git
    
  8. To verify the new upstream repository you specified for your fork, type git remote -v again. You should see the URL for your fork as origin and the URL for the upstream repository as upstream.

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

You can now keep your fork synced with the upstream repository with a few Git commands. See Syncing a fork.

Remarque

Pour plus d’informations sur GitHub CLI, consultez À propos de l’interface CLI GitHub.

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

gh repo fork REPOSITORY --remote=true

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

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

Editing a fork

You can make any changes to a fork, including:

  • Creating branches: Branches allow 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 submit a pull request to ask the original author to pull your fork into their repository. See Creating a pull request from a fork.

Find another repository to fork

Fork a repository to start contributing to a project. Vous pouvez dupliquer n’importe quel référentiel public :

  • Vers votre compte personnel
  • Vers une organisation où vous avez l’autorisation de créer des référentiels

Si vous avez accès à un référentiel privé et que le propriétaire autorise la duplication, vous pouvez dupliquer le référentiel :

  • Vers votre compte personnel
  • Vers une organisation sur GitHub Team où vous avez l’autorisation de créer des référentiels

Vous ne pouvez pas dupliquer un dépôt privé vers une organisation en utilisant GitHub Free. Pour plus d’informations sur GitHub Team et GitHub Free, consultez plans de GitHub.

For more information about when you can fork a repository, see Forks.

You can browse Explore GitHub to find projects and start contributing to open source repositories. See Trouver des moyens de contribuer à open source sur GitHub.

Next steps

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

  • For more information about using Git on the command line to clone and sync changes, see Configurer Git.

  • You can also create a new repository to store your projects and share the code on GitHub. La création d’un référentiel pour votre projet vous permet de stocker du code dans GitHub. Cela fournit une sauvegarde de votre travail que vous pouvez choisir de partager avec d’autres développeurs. Pour plus d’informations, consultez « Guide de démarrage rapide pour les dépôts ».

  • Chaque dépôt sur GitHub appartient à une personne ou à une organisation. Vous pouvez interagir avec les personnes, les dépôts et les organisations en les connectant et en les suivant sur GitHub. Pour plus d’informations, consultez « Trouver de l’inspiration sur GitHub ».

  • GitHub dispose d’une vaste communauté de support dans laquelle vous pouvez demander de l’aide et parler avec des personnes du monde entier. Participez à la conversation dans GitHub Community.