Bird
Raised Fist0
Gitdevops~20 mins

Sparse checkout for partial repos in Git - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sparse Checkout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Sparse checkout initialization output
You run these commands in a new Git repository:

git init
git remote add origin https://example.com/repo.git
git config core.sparseCheckout true
echo "docs/" > .git/info/sparse-checkout
git pull origin main

What will be the output or result of the last command?
ANo files are checked out; the working directory remains empty.
BThe entire repository is downloaded and checked out locally.
CGit throws an error because sparse checkout is not supported in this sequence.
DOnly the 'docs/' folder and its contents are downloaded and checked out locally.
Attempts:
2 left
💡 Hint
Sparse checkout allows you to check out only parts of the repo you want.
🧠 Conceptual
intermediate
1:30remaining
Understanding sparse-checkout file format
Which of the following lines in the .git/info/sparse-checkout file will include all files inside the 'src' directory and its subdirectories?
Asrc/*
Bsrc/
C/src
Dsrc
Attempts:
2 left
💡 Hint
Trailing slash means directory and all contents.
🔀 Workflow
advanced
2:30remaining
Steps to enable sparse checkout on an existing repo
You have cloned a large repository fully. Now you want to enable sparse checkout to keep only the 'config/' folder locally. Which sequence of commands correctly achieves this?
Agit config core.sparseCheckout true<br>echo "config/" > .git/info/sparse-checkout<br>git read-tree -mu HEAD
Becho "config/" > .git/info/sparse-checkout<br>git config core.sparseCheckout true<br>git checkout HEAD
Cgit sparse-checkout init<br>git sparse-checkout set config/
Dgit config core.sparseCheckout true<br>git checkout config/
Attempts:
2 left
💡 Hint
You must enable sparse checkout, set the patterns, then update the working tree.
❓ Troubleshoot
advanced
2:00remaining
Sparse checkout not working as expected
You enabled sparse checkout and set the sparse-checkout file to include 'app/'. But after pulling, you still see all files checked out. What is the most likely cause?
AThe core.sparseCheckout setting is not enabled (false).
BThe remote URL is incorrect.
CThe branch name is misspelled in the pull command.
DThe sparse-checkout file has incorrect file permissions.
Attempts:
2 left
💡 Hint
Sparse checkout must be explicitly enabled in Git config.
✅ Best Practice
expert
3:00remaining
Efficient sparse checkout with Git's built-in commands
Which command sequence uses Git's built-in sparse-checkout commands to initialize sparse checkout and set it to only the 'frontend/' and 'backend/' folders?
Agit config core.sparseCheckout true<br>echo "frontend/\nbackend/" > .git/info/sparse-checkout<br>git read-tree -mu HEAD
Bgit sparse-checkout init<br>git sparse-checkout add frontend backend
Cgit sparse-checkout init --cone<br>git sparse-checkout set frontend backend
Dgit sparse-checkout enable<br>git sparse-checkout include frontend backend
Attempts:
2 left
💡 Hint
Use the new sparse-checkout commands with cone mode for simplicity.

Practice

(1/5)
1. What is the main purpose of using git sparse-checkout?
easy
A. To merge two branches automatically
B. To clone a repository faster by skipping all files
C. To delete files from the repository permanently
D. To download only specific parts of a repository you need

Solution

  1. Step 1: Understand sparse checkout concept

    Sparse checkout allows you to work with only parts of a repo instead of the whole repo.
  2. Step 2: Identify the main purpose

    This helps save space and time by downloading only needed folders or files.
  3. Final Answer:

    To download only specific parts of a repository you need -> Option D
  4. Quick Check:

    Sparse checkout = partial repo download [OK]
Hint: Sparse checkout means partial repo download only [OK]
Common Mistakes:
  • Thinking it deletes files from the repo
  • Confusing with branch merging
  • Assuming it skips all files
2. Which command correctly initializes sparse checkout with cone mode?
easy
A. git sparse-checkout start --cone
B. git sparse-checkout init --cone
C. git sparse-checkout enable --cone
D. git sparse-checkout create --cone

Solution

  1. Step 1: Recall the correct initialization command

    The official command to start sparse checkout in cone mode is git sparse-checkout init --cone.
  2. Step 2: Verify other options

    Other commands like start, enable, or create are not valid git sparse-checkout commands.
  3. Final Answer:

    git sparse-checkout init --cone -> Option B
  4. Quick Check:

    Init with --cone = git sparse-checkout init --cone [OK]
Hint: Use 'init' with '--cone' to start sparse checkout [OK]
Common Mistakes:
  • Using 'start' instead of 'init'
  • Forgetting the '--cone' flag
  • Using invalid verbs like 'enable' or 'create'
3. After running git sparse-checkout set docs src, which folders will be present in your working directory?
medium
A. No folders, only files at root
B. All folders except 'docs' and 'src'
C. Only the 'docs' and 'src' folders
D. All folders in the repository

Solution

  1. Step 1: Understand the effect of 'git sparse-checkout set'

    This command sets which folders to include in the working directory.
  2. Step 2: Analyze the given folders

    Setting 'docs' and 'src' means only these two folders will be checked out and visible.
  3. Final Answer:

    Only the 'docs' and 'src' folders -> Option C
  4. Quick Check:

    Set folders = only those folders appear [OK]
Hint: Set folders to include with 'git sparse-checkout set' [OK]
Common Mistakes:
  • Assuming all folders remain
  • Thinking it excludes specified folders
  • Expecting files outside these folders to appear
4. You ran git sparse-checkout set src but still see all folders. What is the likely mistake?
medium
A. You forgot to run git sparse-checkout init --cone first
B. You used the wrong folder name in the set command
C. You need to delete the .git folder to apply changes
D. Sparse checkout does not work on folders, only files

Solution

  1. Step 1: Check sparse checkout initialization

    Before setting folders, you must initialize sparse checkout with git sparse-checkout init --cone.
  2. Step 2: Understand why all folders appear

    If not initialized, sparse checkout settings are ignored, so all folders remain visible.
  3. Final Answer:

    You forgot to run git sparse-checkout init --cone first -> Option A
  4. Quick Check:

    Init missing = no sparse effect [OK]
Hint: Always init sparse checkout before setting folders [OK]
Common Mistakes:
  • Skipping initialization step
  • Deleting .git folder unnecessarily
  • Believing sparse checkout works only on files
5. You want to work only on the frontend and backend/api folders in a large repo. Which sequence of commands correctly sets this up?
hard
A. git sparse-checkout init --cone git sparse-checkout set frontend backend/api
B. git sparse-checkout set frontend backend/api git sparse-checkout init --cone
C. git sparse-checkout init git sparse-checkout set frontend backend/api
D. git sparse-checkout init --cone git sparse-checkout add frontend backend/api

Solution

  1. Step 1: Initialize sparse checkout with cone mode

    Use git sparse-checkout init --cone to enable sparse checkout in cone mode.
  2. Step 2: Set the folders to include

    Use git sparse-checkout set frontend backend/api to specify the folders you want.
  3. Step 3: Verify command order and syntax

    Initialization must come before setting folders; 'add' is not a valid command.
  4. Final Answer:

    git sparse-checkout init --cone git sparse-checkout set frontend backend/api -> Option A
  5. Quick Check:

    Init then set folders = correct sequence [OK]
Hint: Init sparse checkout first, then set folders [OK]
Common Mistakes:
  • Setting folders before initialization
  • Using 'add' instead of 'set'
  • Omitting the '--cone' flag during init
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard