Graphite Reviewer is now Diamond

Git cloning vs forking

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


In software development, you'll often encounter the terms "forking" and "cloning." These commands both serve distinct purposes and are used in different scenarios. In this guide, we'll explore the differences between forking and cloning and when to use them.

Cloning is the process of making a local copy of a repository from a version control system like Git. When you clone a repo, you download a copy of its entire history, branches, and files to your local machine. This allows you to work on the project offline, make changes, and then push those changes back to the remote repository if you have the necessary permissions.

Suppose you want to contribute to an open-source project on GitHub. You would start by cloning the repository to your local machine using the following Git command:

Terminal
git clone https://github.com/username/repository-name.git

After executing this command, you'll have a complete copy of the repository's files and history on your local machine. You can now edit files, commit changes, and push updates back to the original repository.

Forking is a concept specific to platforms like GitHub, GitLab, and Bitbucket. It involves creating a personal copy of someone else’s repository on your account. This copy is remote (hosted on the platform) and independent of the original repository. Forking allows you to freely experiment with changes without affecting the original project.

After forking a repository, you can clone your fork to your local machine, make changes, and push the changes back to your fork. If you want these changes to be included in the original repository, you can submit a pull request.

On GitHub, you can fork a repository by navigating to the repository's page and clicking the "Fork" button. This creates a copy of the repository under your GitHub account.

Imagine you find a project on GitHub that you think could benefit from some enhancements or you have found a bug to fix. You can fork the project by clicking the "Fork" button on the repository's page on GitHub. This creates a copy under your GitHub account. You can then clone this fork locally:

Terminal
git clone https://github.com/yourusername/forked-repository-name.git

You make your changes locally and push them back to your fork on GitHub. To propose these changes to the original repository, you'd open a pull request.

  1. Ownership and permissions:

    • Cloning does not change the ownership of the repository. You clone a repository to make a local copy, but you cannot push changes unless you have permissions.
    • Forking creates a new repository under your account, giving you full control over the repository. You can make changes, push updates, and manage it as your own project.
  2. Purpose and use-cases:

    • Cloning is typically used when you want to work directly with the original repository and have the permissions to do so. It’s common in scenarios where team members are collaborating on a project.
    • Forking is used when you want to develop the project independently, suggest changes via pull requests, or diverge from the original vision without impacting the original repository. It’s ideal for contributing to open-source projects where you don’t have direct write access.
  3. Scope of changes:

    • Changes in a cloned repository impact the original repository directly once pushed and merged.
    • Changes in a forked repository remain in your personal copy until you decide to issue a pull request and the original maintainer merges it.

Understanding when to fork and when to clone is very beneficial in the world of collaborative software development. Forking allows you to take a project in a new direction or contribute back to the original with pull requests, while cloning is about personal or team work within the existing framework of a project. By choosing the right approach based on your needs and permissions, you can then collaborate and contribute to software projects.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone