This Git warning appears when running sparse-checkout commands on a repository that hasn't been initialized for sparse checkout. Enable sparse checkout with 'git sparse-checkout init' or disable the feature to resolve it.
This warning message appears when you attempt to use Git sparse-checkout commands (like `git sparse-checkout list` or `git sparse-checkout set`) on a repository where sparse checkout has not been properly initialized. Git is informing you that the sparse-checkout configuration file doesn't exist or the feature hasn't been enabled. Sparse checkout is a Git feature designed for working with large repositories, particularly monorepos, where you only need a subset of the files in your working directory. It was significantly improved in Git 2.25.0 with the introduction of the `git sparse-checkout` command, making it easier to manage which directories and files are checked out. The warning indicates that either the `core.sparseCheckout` configuration option is not set to `true`, or the sparse-checkout patterns file (located at `.git/info/sparse-checkout`) doesn't exist. Without proper initialization, Git cannot determine which files should be included in your working directory.
First, check if sparse checkout is enabled and examine the current configuration:
# Check if sparse checkout is enabled
git config --get core.sparseCheckout
# Check if sparse-checkout file exists
ls -la .git/info/sparse-checkout
# List current sparse-checkout patterns (this may show the warning)
git sparse-checkout list
# Check the repository's sparse-checkout status
git statusIf core.sparseCheckout returns nothing or false, sparse checkout is not enabled.
Use git sparse-checkout init to properly set up sparse checkout:
# Initialize sparse checkout in cone mode (recommended, faster)
git sparse-checkout init --cone
# Or initialize in legacy pattern mode
git sparse-checkout init --no-coneCone mode (default in newer Git versions) is more performant and limits patterns to directory-based matching. In cone mode, you specify directories to include.
Non-cone mode uses gitignore-style patterns, offering more flexibility but with performance tradeoffs.
After initialization, verify:
git config --get core.sparseCheckout
# Should output: trueAfter initialization, specify which directories you want to check out:
# In cone mode - specify directories to include
git sparse-checkout set dir1 dir2/subdir
# Add additional directories without replacing existing ones
git sparse-checkout add dir3
# List current patterns
git sparse-checkout listExample for a monorepo:
# Check out only the frontend app and shared libraries
git sparse-checkout set apps/frontend libs/sharedYour working directory will now only contain:
- The root files (always included in cone mode)
- The specified directories and their contents
For new clones, you can enable sparse checkout during the clone operation:
# Clone without checking out files
git clone --no-checkout <repository-url> <directory>
# Navigate to the directory
cd <directory>
# Initialize sparse checkout
git sparse-checkout init --cone
# Set the directories you want
git sparse-checkout set path/to/dir1 path/to/dir2
# Now checkout to get the files
git checkout mainOr use the --sparse flag (Git 2.25+):
# Clone with sparse checkout initialized
git clone --sparse <repository-url>
# Then set your directories
git sparse-checkout set apps/myappThis approach is faster for large repositories since you never download all files to the working directory.
If you don't need sparse checkout and want to get rid of the warning:
# Disable sparse checkout and restore all files
git sparse-checkout disableThis command:
1. Sets core.sparseCheckout to false
2. Removes the sparse-checkout patterns
3. Restores all files to the working directory
Manual cleanup if needed:
# Manually disable the config
git config core.sparseCheckout false
# Remove the sparse-checkout file
rm .git/info/sparse-checkout
# Restore all files
git checkout HEAD -- .After disabling, git sparse-checkout list will show the warning again, which is expected when sparse checkout is disabled.
If the warning persists after initialization, check for configuration issues:
# Show all config values and their sources
git config --list --show-origin | grep sparse
# Check worktree-specific config (if using worktrees)
git config --worktree --listFor worktree issues:
# Sparse checkout is per-worktree, check extensions
git config extensions.worktreeConfig
# If true, check .git/config.worktree exists
cat .git/config.worktreeRe-initialize if corrupted:
# Disable and re-enable
git sparse-checkout disable
git sparse-checkout init --cone
git sparse-checkout set <your-directories>### Sparse Checkout Modes Explained
Git sparse checkout supports two modes:
Cone Mode (Recommended)
- Introduced in Git 2.26
- Patterns are limited to directories
- Significantly faster for large repositories
- Uses a more efficient algorithm for pattern matching
- Default mode in recent Git versions
Non-Cone Mode (Legacy)
- Uses gitignore-style patterns
- More flexible but slower
- Useful when you need file-level patterns
### The Sparse-Checkout File Format
The .git/info/sparse-checkout file contains patterns:
Cone mode patterns:
/*
!/*/
/apps/
/apps/frontend/
/libs/
/libs/shared/Non-cone mode patterns:
# Include all files in docs
docs/**
# Include specific file types in src
src/**/*.ts
src/**/*.tsx
# Exclude test files
!**/*.test.ts### Sparse Index (Git 2.32+)
The sparse index feature improves performance further by not expanding the full index:
# Enable sparse index
git sparse-checkout init --cone --sparse-index
# Check if sparse index is enabled
git config --get index.sparseWarning: Some older tools may not support sparse index. If you encounter compatibility issues:
git sparse-checkout init --cone --no-sparse-index### Windows-Specific Issues
On Windows, line endings in the sparse-checkout file can cause problems:
# Use Git Bash, not PowerShell/CMD
# The sparse-checkout file must use Unix line endings (LF)
# If you edited manually, fix line endings
cd .git/info
dos2unix sparse-checkout### Common Workflows
CI/CD Pipeline Optimization:
# GitHub Actions example
- uses: actions/checkout@v4
with:
sparse-checkout: |
src
package.json
sparse-checkout-cone-mode: trueWorking with Git Worktrees:
Each worktree has its own sparse-checkout configuration:
# Main worktree
git sparse-checkout set apps/backend
# Create worktree for frontend work
git worktree add ../frontend-worktree main
cd ../frontend-worktree
git sparse-checkout init --cone
git sparse-checkout set apps/frontend### Version Compatibility
| Feature | Git Version |
|---------|-------------|
| Basic sparse-checkout | 1.7.0+ |
| git sparse-checkout command | 2.25.0+ |
| Cone mode | 2.26.0+ |
| Sparse index | 2.32.0+ |
| --sparse clone flag | 2.25.0+ |
### Debugging Sparse Checkout
# Verbose output for troubleshooting
GIT_TRACE=1 git sparse-checkout list
# Check which files are marked as skip-worktree
git ls-files -t | grep ^S
# Show files that should be present based on patterns
git sparse-checkout checkwarning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server