skillfed

gitmatch

Gitignore-style path matching

gitmatch v0.3.0 87.7K downloads/30d#13,771 on PyPI4
Permissive license MIT Active released

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 gitmatch

uv

uv add gitmatch

poetry

poetry add gitmatch

Installing 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

Intended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Version Control :: GitTopic :: Text Processing :: FiltersTyping :: Typed

Tags

gitignore pattern matchingpath matching with gitignore syntaxwildcard file path filteringfnmatch glob patternsgitignore-style path filtering
gitignorepattern-matching

More Filters packages