📖 Scenario: You are working on a large project repository but only need to work with a small part of it. Downloading the entire repository wastes time and space. Sparse checkout lets you download only the folders or files you need.
🎯 Goal: Learn how to set up sparse checkout in Git to clone only a specific folder from a repository.
📋 What You'll Learn
Use Git commands to initialize a repository
Enable sparse checkout
Configure sparse checkout to include only a specific folder
Pull the partial content and verify the folder is present
💡 Why This Matters
🌍 Real World
Sparse checkout helps developers work efficiently with large repositories by downloading only needed parts, saving time and disk space.
💼 Career
Many companies use large monorepos. Knowing sparse checkout is useful for developers, DevOps engineers, and release managers to optimize workflows.
Progress0 / 4 steps
1
Initialize a new Git repository and add remote
Run git init to create a new Git repository. Then add the remote repository URL using git remote add origin https://github.com/example/large-repo.git.
Git
Hint
Use git init to start a repo and git remote add origin to link the remote URL.
2
Enable sparse checkout in the repository
Enable sparse checkout by running git config core.sparseCheckout true.
Git
Hint
Use git config core.sparseCheckout true to turn on sparse checkout.
3
Specify the folder to checkout sparsely
Create the file .git/info/sparse-checkout and add the line docs/ to specify you want only the docs folder.
Git
Hint
Use echo "docs/" > .git/info/sparse-checkout to write the folder path.
4
Pull the partial repository content and verify
Run git pull origin main to download only the docs folder. Then run ls docs to list the contents of the docs folder.
Git
Hint
Use git pull origin main to fetch the partial repo, then ls docs to see the files.
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
Step 1: Understand sparse checkout concept
Sparse checkout allows you to work with only parts of a repo instead of the whole repo.
Step 2: Identify the main purpose
This helps save space and time by downloading only needed folders or files.
Final Answer:
To download only specific parts of a repository you need -> Option D
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
Step 1: Recall the correct initialization command
The official command to start sparse checkout in cone mode is git sparse-checkout init --cone.
Step 2: Verify other options
Other commands like start, enable, or create are not valid git sparse-checkout commands.
Final Answer:
git sparse-checkout init --cone -> Option B
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
Step 1: Understand the effect of 'git sparse-checkout set'
This command sets which folders to include in the working directory.
Step 2: Analyze the given folders
Setting 'docs' and 'src' means only these two folders will be checked out and visible.
Final Answer:
Only the 'docs' and 'src' folders -> Option C
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
Step 1: Check sparse checkout initialization
Before setting folders, you must initialize sparse checkout with git sparse-checkout init --cone.
Step 2: Understand why all folders appear
If not initialized, sparse checkout settings are ignored, so all folders remain visible.
Final Answer:
You forgot to run git sparse-checkout init --cone first -> Option A
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
Step 1: Initialize sparse checkout with cone mode
Use git sparse-checkout init --cone to enable sparse checkout in cone mode.
Step 2: Set the folders to include
Use git sparse-checkout set frontend backend/api to specify the folders you want.
Step 3: Verify command order and syntax
Initialization must come before setting folders; 'add' is not a valid command.
Final Answer:
git sparse-checkout init --cone
git sparse-checkout set frontend backend/api -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.