0
0
Gitdevops~20 mins

Why submodules manage nested repos in Git - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Submodule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use Git submodules for nested repositories?

Which of the following best explains why Git submodules are used to manage nested repositories?

AThey allow a repository to include and track a specific commit of another repository as a subdirectory.
BThey automatically merge changes from nested repositories into the main repository without manual intervention.
CThey convert nested repositories into branches within the main repository for easier management.
DThey duplicate the entire nested repository content inside the main repository to avoid external dependencies.
Attempts:
2 left
💡 Hint

Think about how Git keeps track of external projects inside a main project.

💻 Command Output
intermediate
2:00remaining
Output of git submodule status command

What is the output of the command git submodule status immediately after cloning a repository with submodules but before initializing them?

Git
git clone https://example.com/project.git
cd project
git submodule status
A 3f4e2a1c7d8b9f0a1234567890abcdef12345678 path/to/submodule (heads/main)
B+3f4e2a1c7d8b9f0a1234567890abcdef12345678 path/to/submodule (detached)
CNo submodules found.
D-3f4e2a1c7d8b9f0a1234567890abcdef12345678 path/to/submodule (new commits)
Attempts:
2 left
💡 Hint

Check the symbol before the commit hash indicating submodule state.

🔀 Workflow
advanced
2:30remaining
Correct workflow to update a submodule to latest commit

Which sequence of commands correctly updates a Git submodule to the latest commit on its default branch and commits this change in the main repository?

A
git submodule update --remote
 git add path/to/submodule
 git commit -m "Update submodule"
B
git submodule sync
 git push
 git commit -m "Update submodule"
C
git clone submodule_url path/to/submodule
 git commit -m "Update submodule"
D
git pull
 git submodule init
 git commit -m "Update submodule"
Attempts:
2 left
💡 Hint

Think about how to fetch latest changes and record them in the main repo.

Troubleshoot
advanced
2:00remaining
Resolving detached HEAD state in submodule

You notice your Git submodule is in a detached HEAD state after updating. Which command fixes this by checking out the submodule's default branch?

Agit submodule sync
Bgit reset --hard HEAD
Ccd path/to/submodule && git checkout main
Dgit submodule update --remote --merge
Attempts:
2 left
💡 Hint

Detached HEAD means you are not on a branch inside the submodule.

Best Practice
expert
3:00remaining
Best practice for committing changes in submodules

When you make changes inside a Git submodule, what is the best practice to ensure the main repository tracks these changes correctly?

ACommit changes only in the main repository; submodule commits are tracked automatically.
BCommit changes inside the submodule, then commit the updated submodule reference in the main repository.
CMake changes and commit only in the submodule; no need to update the main repository.
DDelete and re-add the submodule after changes to refresh the main repository tracking.
Attempts:
2 left
💡 Hint

Think about how Git tracks submodule versions inside the main repo.