0
0
Gitdevops~20 mins

Adding a submodule in Git - Practice Problems & Coding Challenges

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!
💻 Command Output
intermediate
2:00remaining
What is the output of adding a submodule?
You run the command git submodule add https://github.com/example/lib.git libs/lib in your repository. What will be the immediate effect?
AA new folder <code>libs/lib</code> is created with the submodule content, and <code>.gitmodules</code> file is updated.
BThe submodule is cloned but no changes are made to <code>.gitmodules</code>.
CThe command fails because the submodule URL is not valid.
DThe submodule is added but the main repository's <code>HEAD</code> is detached.
Attempts:
2 left
💡 Hint
Think about what files git updates when adding a submodule.
🧠 Conceptual
intermediate
1:30remaining
What does the .gitmodules file contain?
After adding a submodule, what is the purpose of the .gitmodules file in your repository?
AIt stores the URL and path of each submodule to track them in the main repo.
BIt contains the commit hashes of the submodule's latest commits.
CIt lists all branches available in the submodule repository.
DIt stores user credentials for accessing the submodule.
Attempts:
2 left
💡 Hint
Think about what information git needs to find the submodule source.
Troubleshoot
advanced
2:30remaining
Why does 'git submodule update' fail after cloning?
You cloned a repository with submodules but running git submodule update --init gives an error: fatal: no submodule mapping found in .gitmodules for path 'libs/lib'. What is the likely cause?
AYou forgot to run <code>git clone --recursive</code> initially.
BThe submodule URL is unreachable due to network issues.
CThe <code>.gitmodules</code> file is missing or corrupted in the cloned repo.
DThe submodule folder was manually deleted after cloning.
Attempts:
2 left
💡 Hint
The error mentions missing mapping in .gitmodules.
🔀 Workflow
advanced
3:00remaining
Correct sequence to add and commit a submodule
What is the correct order of commands to add a submodule and commit it to your repository?
A2,1,3,4
B1,3,2,4
C1,2,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Remember you must add files before committing.
Best Practice
expert
3:00remaining
Best practice for updating submodules in a team
Your team uses git submodules. What is the best practice to ensure everyone has the latest submodule changes after pulling the main repository?
AOnly run <code>git pull</code> since submodules update automatically.
BRun <code>git clone</code> again to get the latest submodules.
CDelete the submodule folder and re-add it with <code>git submodule add</code> after pulling.
DRun <code>git pull</code> then <code>git submodule update --init --recursive</code> to sync submodules.
Attempts:
2 left
💡 Hint
Submodules require explicit update commands after pulling.