How to fix warning: unrecognized pattern in Git

GitINTERMEDIATELOWUpdated Dec 6, 2025ยท 295 views

This Git warning occurs when sparse-checkout patterns don't match the expected format for cone mode. Git rejects complex glob patterns like '**/*.js' when cone mode is enabled. Switch to non-cone mode or use directory-based patterns to resolve this.

Quick fix

Fixes warning: unrecognized pattern

# Check if cone mode is active
git config core.sparseCheckoutCone

# List current patterns
git sparse-checkout list

# View the raw sparse-checkout file
cat .git/info/sparse-checkout
  1. Check your current sparse-checkout mode
  2. Option 1: Use directory patterns (cone mode compatible)
  3. Option 2: Switch to non-cone mode for complex patterns
  4. Fix negative pattern warnings
git โ€” error
# Check if cone mode is active
git config core.sparseCheckoutCone
# List current patterns
git sparse-checkout list
# View the raw sparse-checkout file
cat .git/info/sparse-checkout
warning: unrecognized pattern

What this error means

This warning appears when you configure `git sparse-checkout` with patterns that don't conform to cone mode's strict requirements. Cone mode, which is the default since Git 2.26, only accepts simple directory-based patterns, not the full gitignore-style patterns you might expect. When Git parses your sparse-checkout file with `core.sparseCheckoutCone=true`, it expects patterns in a specific format: directory paths that start with `/` and optionally end with `/`. Complex glob patterns like `**/*.csv`, `!exclude-dir/`, or patterns with wildcards in directory names are considered "unrecognized" because they don't fit cone mode's optimized path matching model. Git issues this warning because it cannot apply cone mode's performance optimizations to non-conforming patterns. Depending on your Git version, it may either fall back to slower pattern matching or ignore the problematic patterns entirely.

Typical symptoms

  • Running 'git sparse-checkout list' shows 'warning: unrecognized pattern'
  • Sparse checkout patterns using '**' wildcards are rejected
  • Negative patterns like '!/path/' trigger 'unrecognized negative pattern' warning
  • Git outputs 'disabling cone pattern matching' after the warning
  • Expected files are not being checked out despite correct-looking patterns
  • 'git sparse-checkout reapply' produces pattern warnings
  • Sparse checkout works in old Git versions but fails after upgrade
  • Patterns copied from .gitignore don't work in sparse-checkout

Common causes

  1. Using glob patterns (like '**/*.js') when cone mode is enabled (default)
  2. Including negative/exclusion patterns ('!path/') in cone mode
  3. Patterns don't start with '/' as required by cone mode
  4. Using wildcard characters in directory names instead of literal paths
  5. Sparse-checkout file was manually edited with invalid syntax
  6. Copying patterns from .gitignore which uses different syntax
  7. Upgrading Git from a version where non-cone was default
  8. Missing trailing slash on directory patterns

How to fix "warning: unrecognized pattern"

1Check your current sparse-checkout mode

First, determine whether cone mode is enabled:

bash
# Check if cone mode is active
git config core.sparseCheckoutCone

# List current patterns
git sparse-checkout list

# View the raw sparse-checkout file
cat .git/info/sparse-checkout

If core.sparseCheckoutCone returns true (or is unset, as true is the default since Git 2.26), you're in cone mode and must use directory-only patterns.

2Option 1: Use directory patterns (cone mode compatible)

Rewrite your patterns to use simple directory paths that work with cone mode:

bash
# Correct cone mode patterns - only directories
git sparse-checkout set src docs lib

# With nested directories
git sparse-checkout set src/components src/utils tests/unit

# Add more directories later
git sparse-checkout add packages/core

Cone mode rules:
- Patterns must be directory names (no file patterns)
- No glob wildcards (*, **, ?)
- No negation patterns (!)
- All files in the root directory are always included

This approach is faster because Git can use optimized bloom filter matching.

3Option 2: Switch to non-cone mode for complex patterns

If you need glob patterns, wildcards, or exclusions, disable cone mode:

bash
# Initialize sparse checkout in non-cone mode
git sparse-checkout init --no-cone

# Or disable cone mode on existing setup
git config core.sparseCheckoutCone false

# Now you can use gitignore-style patterns
git sparse-checkout set --no-cone '**/*.js' '**/*.ts' '!node_modules/'

Non-cone mode pattern examples:

bash
# Include only JavaScript files
git sparse-checkout set --no-cone '**/*.js'

# Exclude specific directories
git sparse-checkout set --no-cone '/*' '!/large-assets/' '!/vendor/'

# Combine multiple patterns
git sparse-checkout set --no-cone 'src/**' 'tests/**' '*.json' '!*.log'

After changing modes, reapply the checkout:

bash
git sparse-checkout reapply
4Fix negative pattern warnings

Negative (exclusion) patterns require non-cone mode:

bash
# This fails in cone mode:
# git sparse-checkout set --cone '/*' '!/big-directory/'

# Use non-cone mode instead:
git sparse-checkout init --no-cone
git sparse-checkout set --no-cone '/*' '!/big-directory/'

Alternative: Use cone mode with directory whitelist:
Instead of excluding, explicitly include only what you need:

bash
# Instead of excluding 'large-assets', include everything else
git sparse-checkout set src lib tests config

This is often more maintainable and gets the performance benefits of cone mode.

5Verify and reapply sparse checkout

After modifying patterns, verify the configuration:

bash
# List the configured patterns
git sparse-checkout list

# Check which files will be checked out (dry run)
git ls-tree -r HEAD --name-only | git check-ignore --stdin -v --no-index

# Reapply the sparse checkout
git sparse-checkout reapply

# Verify the working directory
ls -la
git status

If files are still not appearing as expected:

bash
# Force a fresh checkout
git read-tree -mu HEAD
6Reset sparse checkout if needed

If sparse checkout is misconfigured, you can reset and start fresh:

bash
# Disable sparse checkout entirely
git sparse-checkout disable

# This checks out all files and removes sparse-checkout config
# Verify everything is restored
git status

# Start over with a clean configuration
git sparse-checkout init --cone  # or --no-cone
git sparse-checkout set your-directories

To completely remove sparse checkout configuration:

bash
git sparse-checkout disable
rm .git/info/sparse-checkout
git config --unset core.sparseCheckout
git config --unset core.sparseCheckoutCone

Advanced notes

### Cone Mode vs Non-Cone Mode

| Feature | Cone Mode | Non-Cone Mode |
|---------|-----------|---------------|
| Pattern syntax | Directory names only | Full gitignore patterns |
| Performance | O(number of patterns) | O(patterns * paths) |
| Negation patterns | Not supported | Supported |
| Glob wildcards | Not supported | Fully supported |
| Sparse index | Compatible | Not compatible |
| Default since | Git 2.26 | Before Git 2.26 |

### Performance Implications

Cone mode uses bloom filters for path matching, making it significantly faster for large repositories. Non-cone mode must check every path against every pattern, which can slow down operations like git status and git checkout considerably in repositories with many files.

For a repository with 100,000 files and 50 patterns:
- Cone mode: ~50 pattern checks (directory-based)
- Non-cone mode: Up to 5,000,000 pattern matches

### Sparse Index Feature

Git 2.32+ introduced the sparse index feature for even better performance:

bash
# Only works with cone mode
git config index.sparse true

This reduces the size of the index file by not including entries for files outside the sparse checkout, but it's incompatible with non-cone mode.

### Editing the Sparse-Checkout File Directly

You can manually edit .git/info/sparse-checkout, but be careful:

bash
# Cone mode expects patterns like:
/path/to/dir/

# Non-cone mode accepts gitignore patterns:
*.txt
!secret.txt
/docs/**

After editing, run git sparse-checkout reapply.

### Git Version Compatibility

- Git 2.25: sparse-checkout command introduced
- Git 2.26: Cone mode becomes default
- Git 2.32: Sparse index feature added
- Git 2.37: Improved warning messages

Older scripts that worked with pre-2.26 Git may need --no-cone added.

### CI/CD Considerations

When using sparse checkout in CI pipelines:

yaml
# GitHub Actions example
- uses: actions/checkout@v4
  with:
    sparse-checkout: |
      src
      tests
      package.json
    sparse-checkout-cone-mode: true

Many CI systems default to cone mode. Use the appropriate option to switch modes if needed.

### Partial Clone + Sparse Checkout

For maximum efficiency with large repositories, combine with partial clone:

bash
# Clone with blob filter (don't download file contents)
git clone --filter=blob:none --sparse https://github.com/user/repo

# Then set sparse checkout
cd repo
git sparse-checkout set src lib

This downloads only the Git objects you actually need.

Frequently asked questions

What does "warning: unrecognized pattern" mean?
This warning appears when you configure git sparse-checkout with patterns that don't conform to cone mode's strict requirements. 26, only accepts simple directory-based patterns, not the full gitignore-style patterns you might expect. sparseCheckoutCone=true, it expects patterns in a specific format: directory paths that start with / and optionally end with /.
How do I fix "warning: unrecognized pattern"?
This Git warning occurs when sparse-checkout patterns don't match the expected format for cone mode. Git rejects complex glob patterns like '*/.js' when cone mode is enabled. Switch to non-cone mode or use directory-based patterns to resolve this.
What causes "warning: unrecognized pattern"?
Using glob patterns (like '*/.js') when cone mode is enabled (default) Including negative/exclusion patterns ('!path/') in cone mode Patterns don't start with '/' as required by cone mode
Is the "warning: unrecognized pattern" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading