0
0
Gitdevops~20 mins

Shallow clones with depth in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shallow Clone Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of shallow clone with depth 1
What is the output of the following command when cloning a large repository with many commits?

git clone --depth 1 https://github.com/example/repo.git

Choose the most accurate description of the clone result.
Git
git clone --depth 1 https://github.com/example/repo.git
AThe repository is cloned with only the latest commit and no earlier history.
BThe repository clone fails because depth must be greater than 1.
CThe repository is cloned with the full commit history but no tags.
DThe repository is cloned with all branches but only the last 10 commits each.
Attempts:
2 left
💡 Hint
Think about what the --depth option limits in a git clone.
🧠 Conceptual
intermediate
2:00remaining
Effect of shallow clone on git log
After cloning a repository with git clone --depth 3, what will git log show compared to a full clone?
AThe log will show commits from all branches, but only 3 per branch.
BAll commits will be shown but with limited details.
COnly the last 3 commits will be shown in the log.
DNo commits will be shown until the full history is fetched.
Attempts:
2 left
💡 Hint
Consider what shallow cloning limits in the commit history.
🔀 Workflow
advanced
2:00remaining
Extending a shallow clone depth
You cloned a repository with git clone --depth 1. Later, you want to fetch more history to depth 5. Which command correctly extends the shallow clone to include the last 5 commits?
Agit fetch --unshallow --depth=5
Bgit pull --depth 5
Cgit clone --depth 5
Dgit fetch --depth=5
Attempts:
2 left
💡 Hint
Think about how to fetch more commits after cloning shallowly.
Troubleshoot
advanced
2:00remaining
Error when pushing from a shallow clone
You cloned a repository with git clone --depth 1 and made commits locally. When you try to push, you get an error:

error: refusing to push because the remote contains work that you do not have locally

What is the most likely cause?
AThe shallow clone lacks full history, so git cannot verify the push is safe.
BYou forgot to add files before committing.
CThe remote repository is read-only.
DYour local branch is not tracking any remote branch.
Attempts:
2 left
💡 Hint
Consider how shallow clones affect push operations.
Best Practice
expert
2:00remaining
Choosing shallow clone depth for CI pipelines
In a continuous integration (CI) pipeline, you want to speed up builds by cloning only necessary commits. Which depth value is best practice to balance speed and build correctness?
AUse full clone without depth to avoid any issues with missing history.
BUse depth 50 to include enough history for most build tools and tests.
CUse depth 1 to clone only the latest commit for fastest builds.
DUse depth 0 to clone no commits and fetch them later as needed.
Attempts:
2 left
💡 Hint
Think about the tradeoff between speed and completeness in CI.