0
0
Gitdevops~30 mins

Sparse checkout for partial repos in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Sparse checkout for partial repos
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use git pull origin main to fetch the partial repo, then ls docs to see the files.