Reflect on your 2024 year in code

Understanding the git fork and pull request workflow

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

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


When collaborating on a large codebase, it’s common that you don’t have direct commit access to the main repository. Instead, you'll have to use a git fork and pull request workflow, where your contributions are initially developed in your personal fork (your own copy) and then proposed to the project’s main repository. This method streamlines collaboration and ensures that code reviews happen before integrating changes into the main branch.

This guide will walk you through the mechanics behind the fork pull request workflows, along with an example scenario of contributing to an open-source project hosted on GitHub. We’ll also explore how tools like the Graphite PR inbox, which centralizes incoming pull requests and code reviews, help teams stay organized.

The core idea is to avoid committing directly to the original repository. Instead, you:

  • create a fork of the repository under your own GitHub account.
  • clone your fork to your local machine and create a feature branch.
  • make your changes and commit them to this branch.
  • push the branch to your fork on GitHub.
  • create a pull request from your fork’s branch into the original repository’s main branch.
  • At the heart of this workflow is the pull request. The maintainers can review your commits, leave feedback, request modifications, and eventually merge your changes into the original repository if they meet the project’s standards.

A fork is a copy of a repository that is hosted under your GitHub account rather than under the original project’s account. Under the hood, GitHub duplicates the repository’s data store (the underlying collection of commits and branches). This means your fork contains all branches, commits, and tags from the original repository at the time of forking. However, you have full control over your fork and can push changes, create new branches, and customize it without affecting the original repository. Here’s how it typically works:

  1. Fork the repository: On GitHub, navigate to the repository you wish to contribute to and click the "Fork" button. This creates a copy under your GitHub account.
  2. Clone your fork: Use the command git clone <url-of-your-fork> to copy the forked repository to your local machine.
  3. Configure remotes: After cloning, it’s crucial to manage your remotes with git remote add upstream <original-repository-url>. This step links your local clone with the original repository, allowing you to fetch updates.

After making your changes in your fork, you can propose these changes to the original repository through a pull request. Here’s the step-by-step:

  1. Create a new branch: Always work in a new branch rather than the main branch. Use git checkout -b <new-feature> to switch to a new branch.
  2. Make changes and commit: After your changes, use git commit -am "Add a concise commit message" to save your work locally.
  3. Push changes to GitHub: With git push origin <new-feature>, you push your branch and changes to your GitHub fork.
  4. Open a pull request: Go to your fork on GitHub, find your branch, and click "New Pull Request". Select the base repository and branch you want to merge your changes into.

Remember:

  • Keep your fork updated: Regularly sync your fork with the original repository to avoid merge conflicts. Use commands like git fetch upstream followed by git merge upstream/main.
  • Squash commits: Before making a pull request, squash your commits into a single, meaningful commit to maintain a clean history. This can be done using git rebase -i.
  • Graphite PR inbox: helps streamline the code review process by providing a single place to track all open pull requests. This prevents overlooking important contributions and keeps the team on the same page.
  • Continuous integration (CI): when you open a pull request, CI pipelines (scripts that run automated tests, style checks, and even security scans) are triggered. If tests fail, you can fix issues before merging. This ensures that the main branch remains stable.
  • Status checks and code owners: GitHub supports requiring status checks (tests and linting tools must pass before merging) and code owners (specific people who must review changes in certain directories), reinforcing code quality.

By combining these tools with the git fork pull request workflow, teams maintain a clean and maintainable codebase while encouraging robust collaboration.

Graphite's pull request inbox acts as an "email client" for your PRs, helping you stay organized and view which PRs need your attention. It allows you to:

  • Filter and customize PR sections: You can create and edit sections with custom filters, similar to email filters, making it easier to manage pull requests based on their status like "Needs your review" or "Approved".
  • Share section configurations: You can share your PR inbox configurations with teammates, ensuring everyone has the same view and settings for managing pull requests.
  • Search across PRs: Integrated fuzzy search lets you quickly find pull requests by title, description, author, and more.

By integrating the git fork pull request workflow with tools like Graphite, teams can enhance their efficiency and collaboration, pushing their development pace while maintaining high standards of code quality.

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