Graphite Reviewer is now Diamond

Polyrepo to monorepo migrations: what teams should know before starting

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite

Migrating from a polyrepo to a monorepo can streamline development workflows, reduce duplication, and improve cross-team collaboration. However, this transition requires careful planning and execution. This guide outlines the key considerations, strategies, and tools to help your team successfully consolidate multiple repositories into a single monorepo.

A monorepo consolidates multiple projects into a single repository, offering several benefits:

  • Simplified dependency management: Shared libraries and components are easier to manage and update.
  • Atomic commits: Changes spanning multiple projects can be made in a single commit, reducing integration issues.
  • Improved visibility: Teams can easily discover and collaborate on code across projects.
  • Consistent tooling: Unified build, test, and deployment processes streamline CI/CD pipelines.

In fact, companies like Google, Facebook, and Twitter have adopted monorepos to manage large-scale systems effectively.

Before initiating a polyrepo to monorepo migration, consider the following steps:

  1. Assess your current repositories: Identify the projects to include in the monorepo and evaluate their dependencies and build processes.

  2. Define the monorepo structure: Decide on a directory layout that reflects your projects' relationships. A common structure is:

    Terminal
    /monorepo
    /apps
    /project-a
    /project-b
    /libs
    /shared-lib
  3. Choose appropriate tooling: Select tools that support monorepo management, such as:

    • Graphite: Facilitates code review workflows in monorepos.
    • Nx: Provides build and test orchestration for monorepos.
    • Bazel: Offers scalable builds for large codebases.
    • Lerna: Manages JavaScript projects with multiple packages.

    These tools can aid in the transition and future management of the monorepo.

  4. Communicate with your team: Ensure all stakeholders understand the migration plan, benefits, and their roles in the process.

To migrate your repositories while preserving history:

  1. Set up the monorepo: Initialize a new Git repository to serve as the monorepo.
  2. Import existing repositories: Use tools like git-filter-repo to merge each repository into the monorepo, maintaining commit history.
  3. Organize the codebase: Place each project's code into its designated directory within the monorepo structure.
  4. Update build and test configurations: Adjust paths and settings to reflect the new monorepo layout.
  5. Set up CI/CD pipelines: Configure continuous integration and deployment processes to work with the monorepo.

For example, Streamdal migrated approximately ten public repositories into a monorepo by planning the directory layout, using a migration script, and ensuring each project's history was preserved.

After the migration:

  • Monitor the monorepo: Keep an eye on build times, test coverage, and developer feedback to identify any issues.
  • Refactor and optimize: Look for opportunities to deduplicate code and improve modularity.
  • Maintain documentation: Update README files, contribution guides, and other documentation to reflect the new structure.
  • Train the team: Provide guidance on working within the monorepo, including best practices for commits, branching, and dependency management.

Migrating from a polyrepo to a monorepo can enhance collaboration, simplify dependency management, and streamline development workflows. By carefully planning the migration, selecting appropriate tools, and engaging your team throughout the process, you can successfully transition to a monorepo structure that supports your organization's growth and efficiency.

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