Data report"State of code review 2024" is now liveRead the full report

Git Monorepo: Best Practices for Scalability

Greg Foster
Greg Foster
Graphite software engineer


Note

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


Managing monorepos with Git can be challenging, especially as the size and complexity of your projects increase. Here's a guide on best practices to ensure your Git monorepo remains scalable and performant.

Understanding Git Monorepo Management

A Git monorepo is a single repository containing multiple projects, which can range from applications to microservices. This structure is beneficial for visibility, collaboration, and standardized tooling across teams​​.

The Origins of Git and Monorepos

Git itself was developed to manage a large project — the Linux kernel — making it inherently suitable for monorepo management. However, as projects grow, performance can become an issue, and strategies must be employed to manage the repository effectively​​.

Tools and Features to Enhance Git Monorepos

There are specific tools and Git features designed to help manage large repositories:

  • Virtual Filesystem for Git (VFS): Allows for streaming support, downloading objects as needed, which is especially useful for very large repositories​​.

  • Sparse Checkouts and Partial Clones: Enable developers to work with a large repository without cloning the entire codebase​​.

  • Git Large File Storage (LFS): An extension for Git that improves support for large files, streamlining push and pull operations​​.

Best Practices for Git Monorepo Scalability

  • Keep History Clean: Use rebase to maintain a linear history, and ensure commits are atomic and relevant to avoid bloating the repository​​.

  • Use Tags and Refs Wisely: Manage the number of refs to prevent performance degradation during operations like clone, fetch, or push​​.

  • Directory Organization: A unified structure helps in easy navigation and discovery within the repository​​.

  • Branch Management: Maintain hygiene by keeping branches small and considering trunk-based development​​.

Handling Performance Issues

As a Git monorepo grows, commands like git log or git blame can slow down due to the large number of commits. To mitigate this, you can:

  • Use git blame with Care: Only run it when necessary, and consider using tools that can bypass the performance issues​​.

  • Optimize Refs: Manage your refs to ensure operations involving them are not hindered by the sheer volume​​.

When to Choose a Git Monorepo

A Git monorepo is often the right choice for projects where unified versioning is essential, and when there is a need for tight collaboration across multiple codebases. However, it's crucial to recognize that not all parts of an organization's software need to be in the same monorepo; unrelated projects can be managed separately​​.

The Future of Git Monorepos

With ongoing investments by companies like Microsoft and the development of open-source tools, the capabilities of Git to handle monorepos are improving, offering more flexibility and overcoming many initial challenges​​.

On this page
Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2