Skip to main content

Fork a repo

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.

About forks

Most commonly, forks are used to either propose changes to someone else's project to which you do not have write access, or to use someone else's project as a starting point for your own idea. You can fork a repository to create a copy of the repository and make changes without affecting 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.com, 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.

Para más información sobre el código abierto, en concreto cómo crear e incrementar un proyecto de código abierto, hemos creado Guías de código abierto que le ayudarán a desarrollar una comunidad de código abierto con la recomendación de procedimientos recomendados para crear y mantener repositorios para un proyecto de código abierto. También puede tomar un curso gratuito de GitHub Skills sobre el mantenimiento de comunidades de código abierto.

Prerequisites

If you have not yet, you should first set up Git. Don't forget to set up authentication to GitHub.com from Git as well.

Forking a repository

You might fork a project to propose changes to the upstream, or original, 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.com, navigate to the octocat/Spoon-Knife repository.
  2. In the top-right corner of the page, click Fork. Fork button
  3. Select an owner for the forked repository. Create a new fork page with owner dropdown emphasized
  4. By default, forks are named the same as their parent repositories. You can change the name of the fork to distinguish it further. Create a new fork page with repository name field emphasized
  5. Optionally, add a description of your fork. Create a new fork page with description field emphasized
  6. Choose whether to copy only the default branch or all branches to the new fork. For many forking scenarios, such as contributing to open-source projects, you only need to copy the default branch. By default, only the default branch is copied. Option to copy only the default branch
  7. Click Create fork. Emphasized create fork button

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

Para obtener más información sobre GitHub CLI, vea "Acerca de 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"

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.com, navigate to your fork of the Spoon-Knife repository.

  2. Encima de la lista de archivos, haga clic en Código. Botón "Código"

  3. Copia la dirección URL del repositorio.

    • Para clonar el repositorio con HTTPS, en «HTTPS» haz clic en .
    • Para clonar el repositorio mediante una clave SSH, incluido un certificado emitido por la entidad de certificación SSH de la organización, haga clic en Usar SSH y luego en .
    • Para clonar un repositorio mediante GitHub CLI, haz clic en GitHub CLI y, después, haz clic en . El icono del portapapeles para copiar la URL para clonar un repositorio con el CLI de GitHub
  4. Abra TerminalTerminalGit Bash.

  5. Cambia el directorio de trabajo actual a la ubicación en donde quieres clonar el directorio.

  6. Type git clone, and 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. Your local clone will be created.

    $ 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.

Para obtener más información sobre GitHub CLI, vea "Acerca de GitHub CLI".

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

gh repo fork REPOSITORY --clone=true
  1. En el menú File, haga clic en Clone Repository.

    Clonar opción de menú en la aplicación Mac

    Opción Clone menu (Clonar menú) en la app de Windows

  2. Haz clic en la pestaña que corresponde a la ubicación del repositorio que deseas clonar. También puede hacer clic en URL para especificar manualmente la ubicación del repositorio.

    Pestañas de ubicación en el menú Clone a repository (Clonar un repositorio)

    Pestañas de ubicación en el menú Clone a repository (Clonar un repositorio)

  3. Elija el repositorio que quiera clonar en la lista.

    Clonar una lista de repositorio

    Clonar una lista de repositorio

  4. Haga clic en Elegir... y navegue hasta una ruta local donde quiera clonar el repositorio.

    El botón Elegir

    El botón Elegir

  5. Haga clic en Clone (Clonar).

    El botón Clonar

    El botón Clonar

Configuring Git to sync your fork with the original repository

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

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

  2. Encima de la lista de archivos, haga clic en Código. Botón "Código"

  3. Copia la dirección URL del repositorio.

    • Para clonar el repositorio con HTTPS, en «HTTPS» haz clic en .
    • Para clonar el repositorio mediante una clave SSH, incluido un certificado emitido por la entidad de certificación SSH de la organización, haga clic en Usar SSH y luego en .
    • Para clonar un repositorio mediante GitHub CLI, haz clic en GitHub CLI y, después, haz clic en . El icono del portapapeles para copiar la URL para clonar un repositorio con el CLI de GitHub
  4. Abra TerminalTerminalGit Bash.

  5. Change directories to the location of 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 current configured remote repository 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, and 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 have specified for your fork, type git remote -v again. You should see the URL for your fork as origin, and the URL for the original 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)

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

Para obtener más información sobre GitHub CLI, vea "Acerca de GitHub CLI".

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 are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

Find another repository to fork

Fork a repository to start contributing to a project. If you have access to a private repository and the owner permits forking, you can fork the repository to your personal account, or an organization on GitHub Team where you have repository creation permissions. You cannot fork a private repository to an organization using GitHub Free. For more information, see "GitHub's products."

You can browse Explore to 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. La creación de un repositorio para el proyecto permite almacenar código en GitHub. Esto proporciona una copia de seguridad del trabajo que puedes elegir compartir con otros desarrolladores. Para obtener más información, consulta «Creación de un repositorio»."

  • Cada repositorio de GitHub le pertenece a una persona u organización. Puedes interactuar con las personas, repositorios y organizaciones conectándote y siguiéndolos en GitHub. Para obtener más información, consulta "Ser social".

  • GitHub tiene una excelente comunidad de soporte técnico en la que puede pedir ayuda y hablar con usuarios de todo el mundo. Únete a la conversación en GitHub Community.