Branching in a Sapling Monorepo

Sapling is a scalable, user-friendly, and open-source source control system that powers Meta’s monorepo. As discussed at the GitMerge 2024 conference session on branching, designing and imple…

9 min readintermediate
--
View Original

Overview

The article discusses the implementation of branching workflows in Meta's Sapling monorepo, focusing on the challenges of scalability and developer experience. It introduces directory branching as a solution to manage multiple versions of code effectively while maintaining a linear commit graph.

What You'll Learn

1

How to implement directory branching in a monorepo using Sapling

2

Why directory branching improves scalability and developer experience in large codebases

3

When to use full-repo branching versus directory branching in a monorepo

Prerequisites & Requirements

  • Understanding of source control systems and branching strategies
  • Familiarity with Sapling source control commands(optional)

Key Questions Answered

What are the challenges of using full-repo branching in a monorepo?
Full-repo branching can lead to performance issues due to wide and non-linear commit graphs, which complicate operations like sl log and sl blame. This approach is not scalable for workflows requiring merging back to the main branch, as it affects the entire repository.
How does directory branching work in Sapling?
Directory branching allows developers to treat directories like traditional repository branches, enabling them to copy, cherry-pick, and merge changes while maintaining a linear commit graph. This approach resolves scalability issues associated with full-repo merges.
What feedback has been received from developers at Meta regarding directory branching?
Developers at Meta have successfully adopted directory branching to manage multiple code versions. It has been particularly useful for maintaining stability during development and for separating production and development versions of code.
When should directory branching be used instead of traditional branching?
Directory branching should be used when continuous integration is expensive, during experimental changes that could disrupt production, or when migrating from Git to a monorepo. It provides flexibility without sacrificing the benefits of a monorepo.

Technologies & Tools

Source Control
Sapling
Used for managing the monorepo at Meta, providing tools for directory branching.
Build System
Buck2
Used for building components that depend on directory branching.

Key Actionable Insights

1
Implement directory branching to manage multiple versions of code without the drawbacks of full-repo branching.
This approach allows teams to maintain a linear commit history while enabling merging workflows at the directory level, enhancing both scalability and developer experience.
2
Utilize the sl subtree command suite for effective directory management in Sapling.
These commands facilitate operations like copying, merging, and cherry-picking changes, which are essential for maintaining code integrity across different versions.
3
Consider using directory branching when CI costs are high or when significant changes could disrupt production.
This strategy allows teams to isolate development efforts from production, providing more control over deployment timelines.

Common Pitfalls

1
Relying solely on full-repo branching can lead to performance issues and a complex commit graph.
This occurs because full-repo merges create wide and non-linear commit histories, which complicate operations and slow down performance for all users.

Related Concepts

Branching Strategies
Source Control Best Practices
Monorepo Management