惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
P
Palo Alto Networks Blog
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
博客园_首页
D
Docker
MyScale Blog
MyScale Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
S
Schneier on Security
C
Check Point Blog
I
Intezer
S
Securelist
雷峰网
雷峰网
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
PCI Perspectives
PCI Perspectives
S
Security @ Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
量子位
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
About on SuperTechFans
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news

Graphite blog

Introducing Code Tours: a new way to review Introducing Cursor Cloud Agents in Graphite Building the future of software development with Cursor Reimagining the PR Page: Designing for speed and focus Graphite changelog [11-20-2025] Graphite changelog [11-04-2025] Graphite changelog [10-16-2025] The future of engineering is collaborative (and already here) Meet Graphite Agent: the next evolution of AI code review Introducing frozen branches: A safer way to build on your teammates’ work Graphite changelog [09-17-2025] How we sped up code search for Graphite Chat Introducing Graphite Chat AI is writing code—here's why it also needs to review that code How I got Claude to write code I could actually ship How we built the first stack-aware merge queue (and why it matters) How we organize our monorepo to ship fast Graphite brings stacking to Tower Code review tooling: Should you build or buy? Making AI code review available to everyone Introducing: The new Graphite + Linear integration Graphite raises $52M and launches Diamond to reimagine code review for the age of AI Why AI will never replace human code review How stacked PRs unblock distributed development teams Graphite is going to Developer Week 2025 Beating the end of year code freeze How Graphite’s eng team ships code remarkably fast Why we chose Anthropic's Claude to power Graphite Reviewer AI code generation will remain fragmented How we redesigned Graphite's landing page in-house Introducing Graphite Reviewer: your AI code review companion How AI code review reduces review cycles to improve developer productivity What if you could get instant feedback on your code? The new developer toolchain Not Rocket Science - How Bors and Google’s TAP inspired modern merge queues Graphite's State of code review 2024 How Google migrated billions of lines of code from Perforce to Piper Going from 0 to 1: How to write better unit tests when there are none Speed up your merges: Parallel CI is now generally available for teams using Graphite’s merge queue Down for less than four minutes a month: how AWS deploys code BitKeeper, Linux, and licensing disputes: How Linus wrote Git in 14 days Graphite is now free for startups and open source projects Launch week wrap-up (May 2024) Reduce CI costs for Buildkite and GitHub Actions Cheaper CI & faster merging with batching How Google does code review The technical learning curve at a startup is gentler than you might think Graphite will now automatically rebase your partially-merged stacks Multiple engineers can now seamlessly collaborate on the same stack of PRs Do you ever outgrow GitHub? From the 80's to 2024 - how CI tests were invented and optimized Graphite changelog [4/10/2024] 🎺 Graphite changelog [4/25/2024] 🐸 How Stack Overflow replaced Experts Exchange How GitHub monopolized code hosting Graphite changelog [3/27/2024] 🤝 The core principles of building a good AI feature Onboarding roulette: deleting our employee accounts daily Graphite changelog [3/13/2024] 🚁 Why Facebook doesn’t use Git How to recreate the Phabricator code review workflow Types of code reviews: Improve performance, velocity, and quality Phabricator vs GitHub vs Graphite: How do they stack up? Improving team velocity through better pull request practices Moving fast breaks things: the importance of a staging environment Building trust as a software engineer Keeping code simple: moving fast by avoiding over-engineering What's better than GitHub pull request filters? The Graphite pull request inbox 7 Best Phabricator alternatives for PR stacking + code review [2024] Accurate eng estimations: predicting and negotiating the future Tracking and understanding GitHub PR stats: A step-by-step guide 8 pull request best practices for optimal engineering What’s next for Graphite Graphite Q1 Launch week: Stacking with the tools you love Graphite Q1 Launch week: Making stacking seamless Accelerating code review The Mom Test How to use stacked PRs to unblock your entire team Graphite Q1 launch week 2024 The practical and philosophical problems with AI code review Empirically sup code review best practices Call site attribution: how to pinpoint rogue SQL queries throttling your performance Every engineer should understand git reflog Post mortem: we took 124 seconds from you, here's 378 back Your GitHub pull request workflow is slowing everyone down Optimizing CI/CD workflows for trunk-based development Why we use AWS instead of Vercel to host our Next.js app How large pull requests slow down development 3 key lessons in application server optimization Trunk-based development: why you should stop using feature branches Git was built in 5 days Why large companies and fast-moving startups are banning merge commits How long should your CI take? Experimenting with AI code review CRA to AppRouter in 5 Steps: A case study with Graphite Graphite Changelog [10/18/2023] The comprehensive guide to writing the best PR title of all time How 10,000 Developers All Contribute to the same Repo
What's the best GitHub pull request merge strategy?
Ninad Pathak · 2024-02-27 · via Graphite blog

When you submit a pull request (PR) on GitHub, you have a few options for merging the changes from your branch into the base branch. The three main strategies are:

  1. Create a merge commit

  2. Squash and merge

  3. Rebase and merge

Choosing the right merge method hinges on your project's goals and the importance of its history. This guide covers the range of that decision-making process, explaining when and why to select each strategy—along with practical examples of how to execute merges.

Common GitHub pull request merge strategies

Before we dive into the specifics of each method, let’s briefly summarize how they differ at a high level:

  • Merge commit: All commits from your branch are added to the base branch history along with an extra merge commit. This method is valuable for maintaining a complete audit trail, especially for collaborators in open-source projects prioritizing transparency.

  • Squash and merge: Your branch commits get combined or “squashed” into a single commit that is then added to the base branch. Squashing simplifies history from experiments, prototypes, and bug hunts.

  • Rebase and merge: Your branch commits get “replayed” one by one on top of the latest base commit. Rebasing keeps centralized stories linear, which can be great for teams with a “mainline” workflow.

GitHub pull request merge strategies 

How do you decide when to create a merge commit versus squash versus rebase? Here is a quick comparison of the main tradeoffs:

Let’s explore each strategy in more depth.

1. Create a merge commit

When merging a pull request on GitHub, the default option creates a "merge commit" that joins the two branch histories. For example, if you have:

* e3851e8 (HEAD, feature/new-module) Complete new module

* a867b4af Fix linting errors

* 6c24fe3 Add initial module code

| \

| * d1485a3 (main) Add login form

* | b6a79f2 Style login button

* | 924565f Fix login bug

Merging this branch would add all three commits to main, plus an additional merge commit:

* e3851e8 (HEAD, feature/new-module) Complete new module

* a867b4af Fix linting errors

* 6c24fe3 Add initial module code

*

* d7e89c1 Merging pull requests

|\

| * d1485a3 (main) Add login form

* | b6a79f2 Style login button

* | 924565f Fix login bug

This approach keeps all commits intact, doesn't edit history, and marks the point of integration.

Behind the scenes, GitHub performs a git merge and commits with the --no-ff flag set to force a merge commit to occur, which guarantees the creation of a merge commit even when it's not strictly necessary.

To merge pull requests, you must have write permissions in the repository.

When to use merge commits 

Here are some situations when you want to use a merge commit when merging a PR:

  • You want to preserve the entire commit history from a feature branch for context.

  • You need to maintain authorship/contribution tracking at a granular level.

  • You want to mark the precise end of a long-running feature branch.

For example, you might use merge commits when integrating work from outside collaborators into an open-source project. Seeing each of their incremental commits can make reviews easier.

The merge commit strategy is best for teams that want to retain a complete record of all changes and commits related to a feature.

2. Squash and merge

The “squash and merge” option on GitHub condenses all the commits from your branch into a single combined commit. For example, if you had three commits:

- Add login form

- Style login button

- Fix login bug

These would get squashed into a single commit:

- Implement login feature

The summarized squash commit replaces the individual commits on your branch.

This approach keeps the default branch history clean without pulling over every small incremental change.

Technically, GitHub performs a fast-forward merge with a single squashed commit. The branch pointer simply progresses to include the work without requiring an explicit merge commit.

When to squash and merge a pull request

Here are a few reasons you may want to use the squash and merge method:

  • You want a simplified commit history focusing on meaningful milestones.

  • You need to clean up work-in-progress commits before merging.

  • Your team simply prefers to squash certain types of branches—such as feature or experimental branches—to keep the main or development branch history clean and focused on significant changes.

Squashing condenses related changes into meaningful milestones. However, you will end up losing authorship details from specific squashed commits.

Teams that prioritize a clean project history over preserving every commit find squash and merge to be the best method.

3. Rebase and merge

The "rebase and merge" strategy integrates a feature branch by replaying its commits onto the main branch.

For example, consider a feature branch with commits:

* Add login form

* Style login button

* Fix login bug

A main branch with recent work:

To rebase and merge:

  1. The engineer individually takes the feature branch commits and applies (or “rebases”) them after the latest main commit, effectively moving the entire feature branch to the head of the main branch.

  2. With the branches now one linear history, main can fast-forward to include the feature work.

The result is a clean project history without unnecessary merge commits:

* Add login form

* Style login button

* Fix login bug

* Login page created

When to use rebase and merge

Consider applying a rebase and merge strategy in these cases:

  • Your team values maintaining a linear commit history on main branches.

  • You want to avoid merge commits cluttering up the repository.

  • You still need to preserve some commit history from the PR branch.

However, rebasing comes with a few drawbacks, including the increased likelihood of conflicts, overwriting shared commit IDs, and loss of original author timestamps. To mitigate these issues and implement rebase and merge effectively, you need to establish team-wide guidelines on what is appropriate while rebasing.

For example, require pull requests to be small and focused to minimize complexity and conflicts. As outlined in code review best practices, keeping changes contained in each pull request to less than 200 lines of code makes them easier to review and rebase without issues.

Also set a policy around appropriate rebasing and small focused pull requests, making this powerful workflow tool easier on both authors and reviewers.

That said, rebasing is appropriate for teams that want linear project history but need more commit context than a full squash would provide. With the cleaned-up commit timeline that rebasing enables, developers can more easily revert changes when needed—they can identify the specific commit that introduced an issue without lots of merge commit clutter getting in the way.

Along with that, the linear history lends itself better to following best practices like "keeping main green," where the main branch always remains in a releasable state—a branch that always successfully compiles and passes all build steps.

Having such an organized, sequential commit history of changes makes it easier for teams to track when issues may have been introduced and quickly fix them before they make it too far downstream.

Key considerations when choosing a merge strategy

When choosing a merge strategy, you should weigh the factors:

  • Commit history: Do engineers need to preserve complete records of incremental developments, or is a summarized view of meaningful milestones preferred?

  • Long-running branches: Long-lived feature branches that remain active for a long time can be difficult to maintain: they can cause issues like complex conflicts during integration or loss of context. Instead, consider using practices like short-lived topic branches.

  • Type of repository: Some repos may benefit from a more simplified history, particularly those focusing on the end product rather than the development process, making a cleaner history more valuable for readability and maintenance.

  • Team preferences: Get consensus from the team on commit history standards.

Rather than enforcing one merge scheme, thoughtfully analyze your collaboration needs and priorities and identify what would work best for you. Whichever merge practice you choose, ensure that you have it documented along with any exception-handling steps.

Is there a better way to merge?

Stacking PRs: The best way to achieve a clean rebasing workflow

A major source of complexity from merge methods comes from long-lived branches containing lots of commits. These tangled histories make merging harder:

  • Merge commits can intertwine disjointed work, cluttering the main branch with a convoluted history.

  • Squashing many unrelated commits can obscure the development narrative, complicating project management.

Rebasing helps resolve these problems when paired with practices like short-lived branches. This enables a stacking workflow that uses rebasing to continually integrate changes into main in small increments helping maintain a clean, linear history on main.

As you eliminate messy merge commits, you start getting a better understanding of how the code evolved by looking at the clean main branch.

Also, when the branches are kept small and short-lived, you minimize complicated merge conflicts that usually occur when rebasing large PRs.

However, the fundamental problem is that massive new features get dumped all at once in a big commit or PR that becomes difficult to manage later.

“The biggest time waster is that PRs wait for review for hours or days. We analyzed historical data for 15 million pull requests, and PRs exist which waited several years to be merged!” — Tomas Riemers

That's where stacking comes in.

Stacking uses rebasing as the primary merging method to keep history linear. Changes get incorporated frequently with stacking workflows rather than massive merges.

Engineering teams at high-velocity companies like Meta, Pinterest, and Coinbase use stacking to simplify code review and integration while unblocking developers.

The result is better teamwork through a linear main history having clear separate steps reflecting incremental work.

The key ideas behind stacking are:

  • Break large tasks into granular, independent chunks.

  • Open small pull requests continually as you make progress.

  • Build features vertically by stacking commits on top of each other.

For example, instead of a single giant PR like this:

You would instead have something like this:

Each unit of work gets reviewed and merged quickly without blocking other changes.

The result is a similar feature, delivered iteratively across a sequence of small pull requests rather than one batch.

Stacking PRs with Graphite

Graphite is a dedicated tool for automating stacking workflows on GitHub.

It helps you:

  • Auto-sync dependent branches.

  • Create and update stacked PRs in bulk.

  • Visualize relationships between branches.

Here’s a high-level comparison of the stacked PR workflow between GitHub and Graphite CLI:

The same stack can be achieved with just three commands when using Graphite.

For example, to create a new stack:

gt add -A

gt create -am "Part 1"

gt create -am "Part 2"

gt create -am "Part 3"

gt submit

Graphite handles all the underlying Git commands needed to rebase branches and propagate changes.

This simplifies merging by structuring work into a series of small, incremental pull requests rather than a single batch.

Transitioning to stacking workflows

Many top tech companies have worked with stacking PR workflows. It works because PRs under 400 lines of code have a higher defect discovery rate than larger PRs.

With stacking, you want the PRs to be less than 200 lines and—ideally—50 lines of code.

The productivity benefits can be immense, but the shift does require adjusting some ingrained processes. Here are a few things you can try to help with the transition.

Do hands-on practice

Encourage developers to divide features into small segments during group sessions and to create small, incremental pull requests that build upon each other. This approach helps the team become familiar with the workflow.

Track what gets fully finished

Prioritize tracking fully completed, shippable features over counting the number of pull requests opened. Adjust dashboards to emphasize the completion of features rather than the number of requests.

Get reviews faster

Accelerate the review process by adding more people with the authority to approve and merge changes to the foundational stack. This strategy prevents delays caused by a few individuals.

Use tools

Leverage purpose-built tools—such as Graphite—to automate complex tasks like updating dependent branches and simplifying the process for everyone involved. You can also consider implementing code linters to expedite initial checks.

Reward good stacking

During meetings, call out great stacking examples and offer praise to new and experienced stackers to encourage these practices. With enough early support and motivation, it may help teams shift to implementing stacked pull requests.

Whether you choose to adopt a stacking workflow or not, the underlying principle remains: be strategic about choosing the best merge method. Here's a breakdown for applying different strategies to suit the needs of your project:

  • Open-source libraries: Use merge commits to keep all contributor history. Don't rewrite public past changes.

  • Prototypes and experiments: Squash everything into major milestones. Hide unrelated small edits.

  • Module libraries: Rebase and merge PRs to maintain clean, linear version histories that are easy to manage.

  • Fast-moving teams in production environments: Default to a stacking workflow that continually rebases into main. This integrates changes frequently in small increments while retaining authorship details. Small, stacked pull requests also enable rapid development while keeping history linear for easy debugging, reverting, and “keeping main green.”

Pick the right merge strategy for your unique workflows

Here's the truth—there's no magic formula we can provide to determine optimal merge practices. 

Every team and project has unique dynamics spanning the spectrum from large enterprise projects to open-source projects with hundreds of collaborators. Ultimately, it's best to identify the workflows that mesh well with your developers' approaches and the level of visibility your team seeks.

Luckily, Graphite automates many potential merge headaches that surface as a dev team grows. It makes managing pull requests and merges easy by fixing the root cause—messy commits.

With Graphite’s integrations across your GitHub repositories, messy merges get automated away behind a friendly interface that just works. You get complete visibility into each step of the feature creation process without the messy branching from main.

Want to try stacking workflows for your team? Give Graphite a spin with the free account and see how the new way of commits and merges can seriously speed up work!