📖 Scenario: You are part of a small software team deciding how to organize your code repositories. You want to understand the difference between using a single repository for all projects (monorepo) versus using separate repositories for each project (multi-repo).
🎯 Goal: Learn how to create and inspect both monorepo and multi-repo setups using git commands. Understand the basic commands to initialize, add files, commit, and check repository status for both approaches.
📋 What You'll Learn
Initialize a git repository
Create files and commit changes
Understand repository structure differences
Use basic git commands: git init, git add, git commit, git status
💡 Why This Matters
🌍 Real World
Software teams often decide between monorepo and multi-repo structures to organize their code. Monorepos keep all projects in one place, making shared code easier to manage. Multi-repos separate projects, which can simplify access control and reduce repository size.
💼 Career
Understanding monorepo vs multi-repo is important for developers and DevOps engineers to manage codebases effectively, collaborate with teams, and maintain CI/CD pipelines.
Progress0 / 4 steps
1
Initialize a monorepo with two projects
Create a new directory called monorepo. Inside it, create two folders named projectA and projectB. Initialize a git repository in monorepo using git init.
Git
Hint
Use mkdir to create folders and git init to start a git repository.
2
Add a config file to the monorepo
Inside the monorepo directory, create a file named config.txt with the text monorepo configuration. Use git add config.txt to stage the file.
Git
Hint
Use echo to write text to a file and git add to stage it.
3
Commit the config file in the monorepo
Commit the staged config.txt file in the monorepo repository with the message Initial commit with config using git commit.
Git
Hint
Use git commit -m "message" to commit staged files with a message.
4
Initialize two separate repositories for multi-repo
Create two directories named projectA and projectB separately. Inside each directory, initialize a git repository using git init. Then create a file named config.txt in each with text projectA config and projectB config respectively. Add and commit these files with messages Initial commit projectA and Initial commit projectB.
Git
Hint
Repeat the steps of creating directories, initializing git, creating files, adding, and committing for each project separately.
Practice
(1/5)
1. Which of the following best describes a monorepo in Git?
easy
A. A repository used only for backups
B. Multiple repositories each containing one project
C. A repository that only stores documentation
D. A single repository containing multiple projects together
Solution
Step 1: Understand the definition of monorepo
A monorepo is a single repository that holds multiple projects or components together in one place.
Step 2: Compare with other options
The other options describe different repository setups or uses, not monorepos.
Final Answer:
A single repository containing multiple projects together -> Option D
Quick Check:
Monorepo = single repo for many projects [OK]
Hint: Monorepo means one repo for many projects [OK]
Common Mistakes:
Confusing monorepo with multi-repo
Thinking monorepo is only for documentation
Assuming monorepo means backup repo
2. Which Git command is commonly used to clone a multi-repo project?
easy
A. git merge
B. git clone
C. git init
D. git push
Solution
Step 1: Identify the command to copy a repository locally
The git clone command copies a remote repository to your local machine.
Step 2: Check other commands for correctness
git merge combines branches, git init creates a new repo, and git push uploads changes.
Final Answer:
git clone <repo-url> -> Option B
Quick Check:
Clone = copy repo locally [OK]
Hint: Clone to copy repo locally, not merge or push [OK]
Common Mistakes:
Using git merge to copy repo
Confusing git init with cloning
Trying to push before cloning
3. You have a monorepo with two projects: frontend and backend. You run git status inside the frontend folder after changing a file in backend. What will you see?
medium
A. Error message about folder mismatch
B. No changes detected because you are inside frontend folder
C. Changes detected for the backend file because monorepo tracks all files
D. Only staged changes shown
Solution
Step 1: Understand monorepo file tracking
In a monorepo, Git tracks all files in the single repository regardless of folder location.
Step 2: Effect of running git status in a subfolder
Running git status anywhere in the repo shows changes in the entire repo, including backend files.
Final Answer:
Changes detected for the backend file because monorepo tracks all files -> Option C
Quick Check:
Monorepo tracks all files, status shows all changes [OK]
Hint: Monorepo status shows all changes, no matter folder [OK]
Common Mistakes:
Thinking git status is folder-limited
Expecting error when running git status in subfolder
Confusing staged changes with all changes
4. A team using multi-repos notices frequent conflicts when updating shared libraries. What is a likely cause?
medium
A. Lack of centralized codebase causes version mismatches
B. Using monorepo causes conflicts
C. Git does not support multiple repositories
D. Developers forgot to commit changes
Solution
Step 1: Analyze multi-repo challenges
Multi-repos separate projects, so shared libraries can have different versions causing conflicts.
Step 2: Eliminate incorrect options
Monorepo is not used here, Git supports multiple repos, and forgetting commits is unrelated to shared library conflicts.
Final Answer:
Lack of centralized codebase causes version mismatches -> Option A
Quick Check:
Multi-repo can cause version conflicts without central code [OK]
Hint: Multi-repo can cause version conflicts without central code [OK]
Common Mistakes:
Blaming monorepo for multi-repo issues
Thinking Git can't handle multiple repos
Ignoring version mismatch as cause
5. Your team has 5 small independent projects with different release schedules and teams. Which repo strategy fits best and why?
hard
A. Multi-repo, because it allows independent work and releases
B. Multi-repo, because it merges all projects into one
C. Monorepo, because it forces all teams to work together
D. Monorepo, because it simplifies dependency management
Solution
Step 1: Analyze project independence and release schedules
Independent projects with different schedules benefit from separate repos to avoid interference.
Step 2: Match repo strategy to team needs
Multi-repo allows teams to work independently and release on their own timelines.
Final Answer:
Multi-repo, because it allows independent work and releases -> Option A
Quick Check:
Independent projects = multi-repo best fit [OK]
Hint: Independent projects with different schedules use multi-repo [OK]
Common Mistakes:
Choosing monorepo for independent projects
Thinking monorepo forces independence
Confusing multi-repo with merging projects
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.