0
0
Gitdevops~5 mins

Cloning with submodules in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Git submodule?
A Git submodule is a repository embedded inside another Git repository. It allows you to keep a separate project within your main project, tracking its own history.
Click to reveal answer
beginner
How do you clone a Git repository including its submodules in one command?
Use git clone --recurse-submodules <repository-url>. This clones the main repo and initializes and updates all submodules automatically.
Click to reveal answer
intermediate
What commands do you run after cloning a repo without --recurse-submodules to get the submodules?
Run git submodule init to initialize submodules, then git submodule update to fetch and checkout the submodule content.
Click to reveal answer
beginner
Why might you want to use Git submodules?
To include and track external projects or libraries inside your project while keeping their histories separate and manageable.
Click to reveal answer
beginner
What happens if you forget to update submodules after cloning a repo?
The submodule folders will be empty or not contain the expected files because the submodule content was not fetched and checked out.
Click to reveal answer
Which command clones a Git repository and all its submodules in one step?
Agit clone <repository-url> --init-submodules
Bgit clone <repository-url> && git submodule update
Cgit clone <repository-url> --submodules
Dgit clone --recurse-submodules <repository-url>
After cloning a repo without submodules, which command initializes the submodules?
Agit submodule fetch
Bgit submodule clone
Cgit submodule init
Dgit submodule checkout
What does git submodule update do?
ADeletes submodules from the repo
BFetches and checks out the submodule content at the commit specified by the main repo
CUpdates the main repository only
DCreates a new submodule
If you want to add a new submodule to your Git repo, which command do you use?
Agit submodule add <repository-url> <path>
Bgit add submodule <repository-url>
Cgit clone --submodule <repository-url>
Dgit submodule init <repository-url>
What is a common problem if you forget to update submodules after cloning?
ASubmodule folders are empty or missing files
BMain repo files are corrupted
CGit refuses to commit changes
DYou cannot push to remote
Explain the steps to clone a Git repository with submodules and ensure all submodules are properly initialized and updated.
Think about cloning and then preparing submodules separately if not done in one step.
You got /3 concepts.
    Describe what a Git submodule is and why it might be useful in a project.
    Imagine including a small project inside a bigger one but keeping it independent.
    You got /4 concepts.