Branching in a Sapling Monorepo

Sapling: Solving Branching Challenges for Meta’s Monorepo

Sapling is a scalable, user-friendly, and open-source source control system that powers Meta’s monorepo. At the GitMerge 2024 conference, we discussed the complexities of designing and implementing branching workflows for large monorepos. These workflows involve challenging tradeoffs between scalability and the developer experience.

Following the conference, we designed, implemented, and open sourced our monorepo branching solution within Sapling. While the code is already open source, this article shares valuable learnings on:

– How we resolved scalability and developer experience tradeoffs in the design and implementation.
– The problems this solution addresses.
– Feedback we received from other developers at Meta.

The key technical insight is that two workflows — non-mergeable full-repo branching and mergeable directory branching — solved all branching-related problems for the wide and diverse set of products built at Meta. We hope Sapling’s open-source code and the insights shared here will benefit the wider industry and open source communities.

### How Source Control Is Handled at Meta

At Meta, engineering teams work within a large monorepo with a single main branch. This approach enables:

– Unified dependency management
– Large-scale refactoring
– Easier collaboration
– Code reuse across projects

However, managing multiple versions of code within this setup presents challenges.

In multi-repo environments, teams typically rely on repository branches to manage different versions. Source control tools like cherry-pick and merge help manage differences between versions effectively.

In contrast, in a monorepo, repository branches are less effective. Branches affect the whole repository, so creating a branch means unrelated projects and dependencies remain frozen and quickly become stale. We refer to this approach as *full-repo branching.*

For workflows that do not require merging back to the main branch — such as product releases where the branch ceases to exist after release — full-repo branching works well. Sapling supports this workflow with the `sl bookmark` family of commands.

However, for product development workflows that require merging back to the main branch, full-repo branching is not scalable. This is because full-repo merges create merge commits with multiple parents, producing a wide (high branching factor) and non-linear commit graph.

In large monorepos, this non-linear history causes performance problems for operations like `sl log` and `sl blame`. Maintaining a mostly linear commit graph, where most commits have a single parent, is crucial for keeping these operations fast for all monorepo users, including those not using branches.

The core limitation is that full-repo branches are all-or-nothing. You cannot create a branch limited to the part of the codebase you own. If you need to patch legacy code or maintain a custom variant for a project, branching forks the entire repository, which is inefficient and cumbersome.

A common workaround was for teams to copy their code into multiple directories. However, this causes loss of standard developer tooling for branch management, resulting in duplicated effort and error-prone manual patching between directories.

### Directory Branching: Sapling’s Monorepo Branching Solution

To address these challenges, we introduced a new set of source control tools in Sapling to implement *directory branching*. This approach bridges the gap between multiple repository branches and maintaining code copies in separate directories.

With directory branching, you can treat directories within the monorepo much like traditional repository branches. You:

– Create branches by copying the code
– Maintain the code by cherry-picking and merging changes between directories
– View history for each directory, including all copies and merges

Crucially, while directory branches support merging between directories, at the repository commit graph level they appear as linear commits. This resolves scalability challenges associated with repo-level merge commits while still providing merging workflows at the directory level.

### How Directory Branching Is Implemented in Sapling

Directory branching in Sapling relies on a series of operations centered around the `sl subtree` command.

– To branch a directory, you use `sl subtree copy` to copy a directory or file — either at the current version or from any historical revision — to a new location in the repository.
– Sapling records metadata in the commit to track the source directory, source revision, and copy relationship, allowing complete recovery of the file histories in the new branch.
– If the code you want to branch is not yet in the monorepo, you can use `sl subtree import` to create a directory branch from an external repository.

Once you have a directory branch, you can use:

– `sl subtree graft` and
– `sl subtree merge`

to cherry-pick or merge changes between directory branches. These commands use the stored metadata to reconstruct directory relationships and perform three-way merges scoped to specific directory content.

The merge algorithm locates the common ancestor of the two directory branches (using the copy metadata) and applies a standard three-way merge as done for traditional repository merges, but limited to the directory content.

### Build System and Developer Tooling Integration

One major advantage of directory branching is that the latest versions of all directory branches are visible simultaneously. This means continuous integration (CI) can test against multiple branches with a single checkout, and teams can be confident no hidden old branches are unexpectedly still in use.

At Meta, we use Buck2 as our build system. When a component depends on another component using directory branching, we use Buck config modifiers (i.e., running `buck build` with the `-m` flag) to select the branch being built.

A downside of directory branching is that code searches may return multiple hits across branches. While it is important to recognize the searched-for code appears in multiple places, this can complicate browsing if results from multiple branches intermix. Advanced code search systems capable of ranking results can mitigate this issue.

### User Feedback on Directory Branching

Directory branching has been widely adopted within Meta by diverse engineering teams to help manage multiple versions of code effectively.

Some teams even combine full-repo branching and directory branching by freezing most of the monorepo on an old commit for stability, while using directory branching to merge changes for specific projects.

We identified three common reasons teams choose directory branching:

1. **Reducing CI costs or avoiding disruption:** Teams separate development and production versions of code, enabling better control over when changes deploy to production.

2. **Collaborative experimental changes:** Large groups collaborate over months on changes that might disrupt production. Directory branching offers better scalability than handling many stacked diffs to simulate a branch.

3. **Migrating from Git:** During migration, teams need equivalents of Git branches within the monorepo to complete consolidation. Directory branching provides this functionality without needing to consolidate all Git branches pre-migration.

Despite these exceptions, having a single version of code remains the monorepo’s default assumption. However, when one of the above scenarios applies, directory branching offers extensive branching workflows without sacrificing monorepo benefits.

### Future Work with Directory Branching

We are exploring leveraging directory branching to improve integration of Git repositories into the Sapling monorepo. Specifically, we plan a lightweight repository migration mechanism:

– Instead of committing all Git repository commits irreversibly into the monorepo history, we create a *soft link* to the external Git repository.
– Sapling can then load Git history on demand, lowering the barrier to entry for Git repositories joining the monorepo.
– This approach facilitates preliminary integrations without committing to migrating full history upfront.

This functionality will be available as an option with the `sl subtree import` command when working with external Git repositories.

Stay tuned — we will publish a dedicated article once we have more insights to share on this exciting advancement.

### Acknowledgements

Many contributors across Meta’s Source Control, Developer Experience, and Open Source teams helped design and implement directory branching in Sapling. We would like to thank:

Chris Cooper, George Giorgidze, Mark Juggurnauth-Thomas, Jon Janzen, Pingchuan Liu, Muir Manders, Mark Mendoza, Jun Wu, and Zhaolong Zhu.

To learn more about Meta Open Source, please visit our [website](https://opensource.fb.com).
https://engineering.fb.com/2025/10/16/developer-tools/branching-in-a-sapling-monorepo/

Philippines gets $400-M ADB loan for insurance sector

MANILA, Philippines – The Asian Development Bank (ADB) on Tuesday announced a $400-million policy-based loan to help boost the Philippines’ insurance sector.

The loan aims to create an enabling environment for broader participation in the industry.

Known as the Insurance Reform Program, Subprogram 1, it will support broader financial sector development reforms in regulation and supervision.

These reforms include promoting greater intermediation of long-term funds to strengthen the insurance market and support economic growth.
https://business.inquirer.net/552594/ph-gets-400-m-adb-loan-for-insurance-sector

Megaworld allots P 3.4B to expand 3 townships

MANILA, Philippines – Developer Megaworld Corp. announced plans to invest PHP 3.4 billion to expand three of its townships across the country.

The company is banking on the strength of its provincial projects to drive growth in the coming years.

In a regulatory filing on Monday, Megaworld revealed that it would reinvest the proceeds raised from selling its shares in its real estate investment trust (REIT) into these expansions.
https://business.inquirer.net/552419/megaworld-allots-p-3-4b-to-expand-3-townships

万博会場解体、跡地再開発へ エンタメ空間、カジノも

くらし
万博会場解体、跡地再開発へ エンタメ空間、カジノも
2025/10/12 16:01(2025/10/12 16:03 更新)
[有料会員限定記事]

大阪市の人工島・夢洲にある大阪・関西万博会場は、閉幕後にほとんどの建築物が解体され、更地に戻される見込みです。

大阪府と大阪市は、この跡地に新たなエンターテインメント空間を整備する方針を打ち出しています。計画案の中には、サーキットやウォーターパークの設置も含まれており、多様なレジャー施設が検討されています。

また、カジノの誘致も視野に入れており、再開発によって地域の活性化を図る意向です。

※この記事は有料会員限定です。
無料トライアルもご利用いただけます。
https://www.nishinippon.co.jp/item/1410475/

India’s journey toward becoming a $35 trillion powerhouse by 2047 hinges on our ability to scale manufacturing sector: Geetanjali Vikram Kirloskar

The 20th CII Manufacturing Summit convened top industry leaders, policymakers, and global experts to redefine India’s manufacturing roadmap. With the sector contributing 17% to GDP, the Confederation of Indian Industry (CII) reaffirmed its commitment to help achieve the long-standing 25% GDP target—a crucial step toward India’s goal of becoming a global manufacturing powerhouse.

Amardeep Singh Bhatia, IAS, Secretary, Department for Promotion of Industry and Internal Trade (DPIIT), Ministry of Commerce & Industry, Government of India, shared in his address, “The remarkable achievement of ₹14 lakh crore in production and ₹5.3 lakh crore in exports has created over 11.5 lakh jobs. This is not just a number; it represents the livelihoods, aspirations, and economic momentum that drives our nation forward. The expansion of our manufacturing portfolio and the rise of mobile phone exports—crossing ₹1.29 lakh crore since 2014—demonstrate India’s capability to compete globally. However, while our manufacturing exports are growing, they still lag behind services exports, signalling an opportunity for transformation.”

Jamshyd N Godrej, Past President, CII; Chairman, CII Manufacturing Summit 2025; and Chairman & Managing Director, Godrej & Boyce Mfg Co Ltd, underscored the urgency of India’s manufacturing evolution:
“The global landscape will not wait for India to catch up. For decades, we have spoken of a 25% GDP share for manufacturing, yet the goalpost continues to shift. Meanwhile, entrepreneurs in Indonesia, Vietnam, and Thailand are launching products in six months, setting benchmarks we must aspire to meet and surpass.”

Beyond competitiveness, Godrej emphasized the need for inclusivity, particularly women’s leadership in manufacturing:
“True transformation will come when more women step into decision-making roles, shaping the future of this industry. While government support remains crucial, the real driving force will be the bold vision of MSMEs, startups, and corporate leaders who push boundaries and challenge conventions.”

Geetanjali Vikram Kirloskar, Chairperson & Managing Director, Kirloskar System Ltd, framed the economic stakes:
“Manufacturing is the backbone of any great economy, and India’s journey toward becoming a $35 trillion powerhouse by 2047 hinges on our ability to scale this sector. Today, at $600 billion, our manufacturing industry represents immense potential—one that must expand beyond 25% of GDP to truly drive national growth.”

Kirloskar also highlighted the critical importance of supply chain and logistics infrastructure:
“In the pursuit of making India a global manufacturing powerhouse, we must recognize that our strength is only as strong as the backbone that supports it—our supply chain and logistics infrastructure. A robust, agile, and resilient supply chain is not just a facilitator; it is a fundamental driver of disruptive innovation and competitiveness in manufacturing.”

Chandrajit Banerjee, Director General, Confederation of Indian Industry (CII), shared a powerful vision:
“India stands at the crossroads of an industrial revolution—one that will define our economic destiny for generations to come. While we celebrate our progress, we must also confront the challenges ahead with unwavering resolve. To transform India from a $3.7 trillion economy to a $30–35 trillion powerhouse by 2047, manufacturing must claim its rightful place—contributing at least 25% to our GDP. This is not just an economic necessity; it is a national imperative.”

He also emphasized that achieving this vision will require more than just rapid growth:
“It will demand bold policy reforms, relentless innovation, and an industry-wide commitment to excellence. The future belongs to those who dare to build it—let this summit be the catalyst that shapes India’s journey to becoming a global manufacturing leader.”

Swati Salgaocar, Chairperson, CII Western Region & President, V M Salgaocar and Brothers Pvt Ltd, highlighted India’s strategic shift:
“India is not an emerging player in manufacturing; it is an evolving powerhouse. We have a strong foundation, and our trajectory is clear: from 17% to 25% of GDP in manufacturing. This gap is not a deficit—it is an open field of opportunity. The question is not just how much we manufacture, but how we do it. Our success will be defined by our ability to embrace intelligent, sustainable, and technologically advanced production models.”

Abheek Singhi, Chair of Practices, Managing Director & Senior Partner, BCG, outlined the need for a fundamental transformation in manufacturing:
“In an era where sustainability is no longer a choice but an imperative, manufacturing must evolve to integrate cutting-edge technology. The fusion of geopolitical realities, digital transformation, and sustainability will define the next industrial revolution. Our ability to scale manufacturing while remaining environmentally conscious is the challenge of our time.”

Summing up the Inaugural Session, Sunil Chordia, Past Chairman, CII Western Region & Chairman, CII WR Sub-Committee on Manufacturing and Chairman & Managing Director, Rajratan Global Wire Ltd, emphasized:
“Progress is not driven by conversations alone; it is propelled by action. As we stand at this turning point, let’s seize the moment—collaborate, innovate, and build a manufacturing ecosystem that is resilient, sustainable, and future-ready. Together, we will establish India as a global manufacturing leader.”

As India moves towards its $35 trillion economy vision by 2047, manufacturing will be at its core. The 20th CII Manufacturing Summit reinforced the need for bold leadership, strategic investment, and policy-driven innovation to establish India as a global manufacturing leader.
https://www.freepressjournal.in/corporate-gallery/indias-journey-toward-becoming-a-35-trillion-powerhouse-by-2047-hinges-on-our-ability-to-scale-manufacturing-sector-geetanjali-vikram-kirloskar

India likely to resolve tariffs issue with US within two months: CEA

Chief Economic Adviser (CEA) V Anantha Nageswaran expressed optimism on Thursday that a resolution to the tariff-related issues with the United States could be reached within the next eight to ten weeks, reported the PTI.

Speaking at an interactive session hosted by the Bharat Chamber of Commerce, Nageswaran said, “Underneath the surface, conversations are going on between the two governments. My hunch is that in the next eight to ten weeks, we will likely see a solution to the tariffs imposed by the US on Indian goods,” according to the PTI.

The United States had imposed an additional 25 per cent tariff on Indian goods from August in response to India’s purchase of Russian oil, bringing the total levy on certain products to 50 per cent. The CEA warned that if these tariffs remain in place, Indian exports to the US could decline.

Describing India as an aspirational lower-middle-income economy, Nageswaran highlighted that the real GDP growth for the first quarter of the current financial year stood at 7.8 per cent. He added that post-pandemic, India has outpaced many other economies in terms of recovery and growth, as per the PTI.

Nageswaran expects the manufacturing, services, and agriculture sectors to play a key role in driving economic progress over the next two years. Consumption and investment, he said, will continue to be the main pillars of growth.

He noted that India has a strong debt-to-GDP ratio, generating more GDP per US dollar of debt compared to many other countries — a sign of efficient capital utilisation. Additionally, rural demand remains resilient, while urban demand is improving.

The recent reduction in GST rates, he said, will result in more disposable income in the hands of consumers, potentially boosting urban consumption, the news agency reported.

The CEA also highlighted that credit to the MSME sector is on the rise, while lending to large industries is undergoing structural change. Resource mobilisation today is well supported by various financial channels.

India’s external sector remains solid despite global headwinds, with robust trade activity and healthy foreign exchange reserves. The current account deficit has eased to just 0.2 per cent of GDP in the first quarter of FY 2025-26.

Regarding the rupee, Nageswaran said, “The rupee is depreciating against the US dollar. But given the underlying strength of the economy, I believe the rupee is likely to stabilise and strengthen in the long term,” as per the PTI.

Outlining the government’s policy priorities, he stressed continued emphasis on capital expenditure, incentives for private investment, and systemic deregulation. Infrastructure development—particularly in ports and airports—has improved, ensuring that economic growth does not lead to overheating, he added.

Touching upon India’s trade with China, he noted that imports are largely composed of capital and intermediate goods. He urged the Indian private sector to increase investment in innovation and research and development (R&D).

On artificial intelligence (AI), Nageswaran remarked that its impact has been limited so far. He cautioned that entry-level coding jobs may be at risk, but overall employment effects are manageable—provided that workers upskill and adapt, the PTI reported.

(With PTI inputs)
https://www.mid-day.com/news/india-news/article/us-tariffs-on-india-india-likely-to-resolve-tariffs-issue-with-us-within-two-months-says-chief-economic-adviser-v-anantha-nageswaran-23594656

Exit mobile version