gitmatch
Gitignore-style path matching
What it is and what it does
Gitmatch is a pure Python library that brings gitignore pattern matching semantics to your code. You compile a list of gitignore-style patterns (including negations with `!` prefix) into a matcher object, then test relative file paths against it to determine if they match. The matcher returns a match object that tells you not just whether a path matched, but which pattern matched it and whether that pattern was a negation.
The library handles the full gitignore syntax including wildcards, directory-only patterns (trailing `/`), and negation rules. It has no external dependencies and runs on Python 3.10+, making it straightforward to embed in tools that need to respect or replicate gitignore behavior without shelling out to git itself.
Use it for:
- Build tools that need to respect .gitignore rules when deciding which files to process or exclude.
- File synchronization or backup utilities that filter paths using gitignore patterns.
- Code generators or linters that should skip files matching project ignore rules.
- Testing frameworks that need to exclude test files or directories based on gitignore patterns.
- Static analysis tools that want to honor ignore patterns without invoking git.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Gitmatch implements gitignore-style pattern matching for file paths, letting you compile patterns and test whether relative paths match them.
Yes. Gitmatch is a focused, well-maintained library with zero dependencies, permissive licensing, and active development. Install it if you need to match file paths against gitignore-style patterns in Python code without shelling out to git. The only constraint is Python 3.10+.
Install
gitmatch on PyPI
pip
pip install gitmatchuv
uv add gitmatchpoetry
poetry add gitmatchInstalling gitmatch
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-07-20 with recent release activity.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects.
Quickstart
import gitmatch
gi = gitmatch.compile(["foo", "!bar", "*.dir/"])
match_result = gi.match("foo/bar")
if match_result:
print(f"Matched pattern: {match_result.pattern}")
Requires Python 3.10 or higher.
Verify before relying
- Exact behavior differences from git's wildmatch implementation (e.g., edge cases in negation or directory matching).
- Performance characteristics on large pattern sets or deeply nested paths.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 252 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 87,742/month — #13,771 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: gitmatch-0.3.0-py3-none-any.whl
Keywords: fnmatch, git, gitignore, glob, wildmatch
Tags
More Filters packages
Pygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
nltkNLTK is a Python library for natural language…
permissive · top 1,000 on PyPI
pandocfiltersProvides Python utilities for writing pandoc…
permissive · top 1,000 on PyPI
UnidecodeConverts Unicode text to ASCII-safe…
copyleft · top 1,000 on PyPI
pymdown-extensionsPymdown Extensions provides a collection of…
permissive · top 1,000 on PyPI
pathspecMatches file paths against gitignore-style…
copyleft · top 100 on PyPI
py-walkFilters filesystem paths using gitignore-style…
permissive · top 5,000 on PyPI
globmatchMatches file paths against glob patterns…
permissive · top 15,000 on PyPI
wcmatchwcmatch provides enhanced file pattern matching…
permissive · top 1,000 on PyPI
ignore-pythonProvides fast recursive directory traversal…
unclear · top 15,000 on PyPI
glob2glob2 extends Python's built-in glob module…
permissive · top 5,000 on PyPI
igittigittA spec-compliant .gitignore parser that matches…
permissive · top 15,000 on PyPI
gitignore-parserParses .gitignore files and returns a callable…
permissive · top 5,000 on PyPI
gitignorantParses .gitignore files and matches file paths…
permissive · top 15,000 on PyPI
ripgrepProvides a Python interface to ripgrep (rg), a…
permissive · top 15,000 on PyPI