0
0
Gitdevops~3 mins

Submodules vs subtrees comparison in Git - When to Use Which

Choose your learning style9 modes available
The Big Idea

Discover how to stop juggling code copies and start managing projects like a pro!

The Scenario

Imagine you have a big project that uses code from other projects. You try to copy and paste those codes manually into your project folder every time they update.

The Problem

This manual copying is slow and confusing. You might forget to update some parts or mix up versions. It's hard to keep track of changes and share your project with others without errors.

The Solution

Using submodules or subtrees in Git helps you link other projects inside your main project cleanly. They keep the code connected and updated without messy copying, making teamwork and updates easier.

Before vs After
Before
Copy code folder from external project
Paste into your project
Repeat on every update
After
git submodule add <repo-url>
OR
git subtree add --prefix=folder <repo-url> main --squash
What It Enables

You can manage external code inside your project smoothly, track updates clearly, and collaborate without confusion.

Real Life Example

A web app uses a shared UI library maintained by another team. Using submodules or subtrees, the app always gets the latest UI updates without manual copying.

Key Takeaways

Manual copying of external code is error-prone and slow.

Submodules link external repos as separate parts, keeping history separate.

Subtrees merge external code into your repo, simplifying management.