Merge Repositories Preserving Both Histories
Zscaler ☯️ Medium Git
Beginner Mode

Start your terminal to use beginner mode.

Scenario:

You have two separate Git repositories at /home/interview/repo-a (5 commits) and /home/interview/repo-b (4 commits) developed independently. Create a new monorepo at /home/interview/monorepo that combines both repositories into separate subdirectories using subtree (project-a/ and project-b/) while preserving the full commit history from both repositories.

Example:

# Before (two separate repositories)
$ cd /home/interview/repo-a && git log --oneline | wc -l
5

$ cd /home/interview/repo-b && git log --oneline | wc -l
4
# After (combined monorepo with both histories)
$ cd /home/interview/monorepo && ls -la
project-a/  project-b/  .git/

$ git log --all --oneline | wc -l
12

$ find project-a/ -type f | wc -l
2

$ find project-b/ -type f | wc -l
2

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →