0
0
Gitdevops~20 mins

Submodules vs subtrees comparison in Git - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Submodules vs Subtrees Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in repository structure between submodules and subtrees
Which statement correctly describes how Git submodules and subtrees manage external repositories within a main project?
ASubmodules keep external repositories as separate folders linked by a commit pointer, while subtrees merge external repositories into the main repository's history.
BSubmodules merge external repositories into the main repository's history, while subtrees keep them as separate folders linked by a commit pointer.
CBoth submodules and subtrees merge external repositories into the main repository's history without keeping separate folders.
DBoth submodules and subtrees keep external repositories as separate folders without merging histories.
Attempts:
2 left
💡 Hint
Think about whether the external code is stored inside the main repo's history or referenced separately.
💻 Command Output
intermediate
2:00remaining
Output of cloning a repository with submodules
What is the output of running the following commands in a fresh directory?
git clone https://example.com/project.git
git submodule update --init --recursive
AClones the main project and submodules but does not initialize them.
BClones only the main project without downloading submodule content.
CClones the main project and initializes all submodules recursively, downloading their content.
DFails with an error because submodules cannot be cloned recursively.
Attempts:
2 left
💡 Hint
Consider what the --init and --recursive flags do for submodules.
🔀 Workflow
advanced
2:00remaining
Updating a subtree to the latest commit from the external repository
Which sequence of commands correctly updates a Git subtree named 'libs/tool' to the latest commit from its remote repository 'https://example.com/tool.git' on branch 'main'?
Agit subtree push --prefix=libs/tool https://example.com/tool.git main
Bgit fetch https://example.com/tool.git && git merge FETCH_HEAD
Cgit submodule update --remote libs/tool
Dgit subtree pull --prefix=libs/tool https://example.com/tool.git main
Attempts:
2 left
💡 Hint
Think about which command pulls and merges changes into the subtree directory.
Troubleshoot
advanced
2:00remaining
Troubleshooting detached HEAD state in submodules
After cloning a repository with submodules and running git submodule update --init, you notice the submodule is in a detached HEAD state. What is the best explanation?
AThe submodule repository is corrupted and cannot checkout branches.
BSubmodules are checked out at a specific commit, not a branch, causing detached HEAD.
CThe main repository forgot to include the submodule's branch information.
DDetached HEAD means the submodule is not initialized properly.
Attempts:
2 left
💡 Hint
Consider how submodules track commits versus branches.
Best Practice
expert
3:00remaining
Choosing between submodules and subtrees for a shared library
You maintain a shared library used by multiple projects. You want to keep the library's history separate, allow independent updates, and avoid complex merge conflicts in the main projects. Which approach is best?
AUse Git submodules to keep the library separate and allow independent updates.
BUse Git subtrees to merge the library history into each project for simpler management.
CCopy the library files manually into each project to avoid Git complexity.
DUse Git subtrees but avoid pushing updates back to the library repository.
Attempts:
2 left
💡 Hint
Think about separation of history and ease of independent updates.