Skip to main content

Line-level git ignore: strip marked lines and blocks before they enter the repository.

Project description

gitignoreline

CI PyPI Python

Line-level git ignore. Mark individual lines or blocks in any source file with a comment, and they will be automatically stripped before commit — your working copy keeps them, the repository never sees them.

Built on git's native clean/smudge filter mechanism, so it works transparently with git add, git commit, and git diff.

Quick Start

# Install (pick one)
uv tool install gitignoreline        # recommended
pip install gitignoreline            # or classic pip

# Set up in your repo
cd your-repo
gitignoreline init

Now mark lines in your code:

host = "localhost"
api_key = "sk-secret-key-12345"  # gitignore
port = 8080

When you git add and git commit, the api_key line is silently removed from the committed file. Your working copy stays unchanged.

How It Works

Working Copy (yours)          Git Repository (shared)
─────────────────────         ──────────────────────
host = "localhost"            host = "localhost"
api_key = "sk-..."  # gi     (line removed)
port = 8080                   port = 8080
  1. gitignoreline init registers a clean filter in .git/config and writes patterns to .gitattributes.
  2. Whenever git stages a file, the clean filter reads it, strips all marked lines/blocks, and passes the sanitised version to git.
  3. The smudge filter is a pass-through (cat), so checkouts are untouched.
  4. Your working copy is never modified — secrets stay local.

Marker Syntax

Single Line

Append the gitignore marker as a comment at the end of the line:

secret = "value"  # gitignore
const key = "abc123"; // gitignore
.secret { display: none; } /* gitignore */
INSERT INTO keys VALUES ('sk-123'); -- gitignore

Block

Wrap multiple lines between start/end markers:

# gitignore-start
AWS_ACCESS_KEY = "AKIA..."
AWS_SECRET_KEY = "wJalr..."
# gitignore-end
// gitignore-start
const config = {
  apiKey: "secret",
  apiSecret: "also-secret",
};
// gitignore-end

Both the marker lines and everything between them are removed from the committed file.

Supported Comment Styles

The comment style is auto-detected from the file extension:

Style Extensions
# gitignore .py, .sh, .yaml, .yml, .toml, .rb, .env, .dockerfile, ...
// gitignore .js, .ts, .tsx, .jsx, .c, .cpp, .java, .go, .rs, .cs, .swift, .kt, ...
-- gitignore .sql, .lua, .hs, .elm, .ada
% gitignore .tex, .m, .erl
<!-- gitignore --> .html, .xml, .svg, .md, .vue
/* gitignore */ .css, .scss, .sass, .less
; gitignore .ini, .asm, .clj, .lisp

Custom extensions can be added via a .gitignoreline config file.

CLI Commands

Command Description
gitignoreline init Set up filters and .gitattributes in the current repo
gitignoreline status Show files and lines with gitignore markers
gitignoreline check Verify no markers leaked into staged content (pre-commit hook)
gitignoreline ci-check Verify no markers in committed content (CI pipeline)
gitignoreline install-hooks Install a git pre-commit hook
gitignoreline save Backup marked lines to .gitignoreline.local
gitignoreline restore Restore marked lines from .gitignoreline.local

gitignoreline init

gitignoreline init                    # Enable for all known extensions
gitignoreline init -e .py -e .js      # Enable only for specific extensions
gitignoreline init --write-config     # Also create a .gitignoreline config template

gitignoreline check / gitignoreline ci-check

gitignoreline check                   # Check staged content (pre-commit)
gitignoreline ci-check                # Check committed content at HEAD (CI)
gitignoreline ci-check --ref main     # Check a specific ref

gitignoreline install-hooks

gitignoreline install-hooks           # Writes .git/hooks/pre-commit

gitignoreline save / gitignoreline restore

gitignoreline save                    # Snapshot marked lines to .gitignoreline.local
gitignoreline restore                 # Re-inject lines from .gitignoreline.local

Enforcing in Teams & Open Source

See quickstart.md for a full enforcement guide. The short version:

  1. Local hooksgitignoreline install-hooks or use the pre-commit framework:
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/h3ll5ur7er/gitignoreline
    rev: v0.1.0
    hooks:
      - id: gitignoreline-check
  1. CI gate — add gitignoreline ci-check to your pipeline:
# .github/workflows/gitignoreline.yml
- run: pip install gitignoreline && gitignoreline ci-check
  1. Branch protection — mark the CI job as a required status check.

Configuration

Create a .gitignoreline file (TOML) in the repository root:

# Map custom extensions to comment styles: [prefix, suffix]
[extensions]
".vue" = ["<!--", "-->"]
".custom" = ["//"]

# Limit which extensions get filter patterns in .gitattributes
[filter]
extensions = [".py", ".js", ".ts", ".yaml"]

Installation

From PyPI

uv tool install gitignoreline        # recommended
pip install gitignoreline            # classic pip
pipx install gitignoreline           # or pipx

From source

git clone https://github.com/h3ll5ur7er/gitignoreline.git
cd gitignoreline
uv tool install .

Development

git clone https://github.com/h3ll5ur7er/gitignoreline.git
cd gitignoreline
uv sync
uv run pytest -v

Important Notes

  • Fresh clones won't have the marked lines — they were never committed. Developers add their own local values, or use gitignoreline restore from a shared .gitignoreline.local.
  • Each developer must run gitignoreline init once per clone to register the filter locally.
  • The .gitattributes file should be committed so the project declares which files use the filter.
  • The .gitignoreline.local store file should not be committed (added to .gitignore automatically).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitignoreline-0.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitignoreline-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file gitignoreline-0.1.0.tar.gz.

File metadata

  • Download URL: gitignoreline-0.1.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitignoreline-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fc9407dd0bd1199de43f1e433d8c53a8ad22ef7f61c767e026d7b9f5a55aea6a
MD5 56a36ed690d4096e9fd1eeb6966240a8
BLAKE2b-256 74ac077ebaacd2decbb678f3a22218388e9c5f6e91beb2e054c13f5b0bc2ee47

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitignoreline-0.1.0.tar.gz:

Publisher: release.yml on h3ll5ur7er/gitignoreline

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gitignoreline-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gitignoreline-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitignoreline-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 332e737e4adbbe2e8a6a2147baf05d953e29e3c2b41e905e336d7fef2df1caaf
MD5 45c23b6d0b6e875a00a0d83eb47db08a
BLAKE2b-256 29253cd7bdd366ebb0a1365989b158b7ce527117979f8e244bcfeb9f2fec62e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitignoreline-0.1.0-py3-none-any.whl:

Publisher: release.yml on h3ll5ur7er/gitignoreline

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page