Skip to the content.

gitignore for AI: .gitignore Templates for Machine Learning, LLM Apps and AI Coding Agents

gitignore-ai is a set of tested .gitignore templates for AI and machine learning projects: model weights and checkpoints (.safetensors, .gguf, .pt, .onnx), datasets, Jupyter notebook checkpoints, experiment tracking folders (Weights & Biases, MLflow, TensorBoard, Lightning, Hydra), local vector databases and LLM caches (Chroma, FAISS, LlamaIndex, LangChain), API keys and .env files, and the personal files AI coding agents write into your repo (Claude Code, Gemini CLI, Aider and others) without hiding the shared agent config your team should commit.

Use them when starting a new ML, RAG or agent project, or when git status shows a 4 GB checkpoint and your .env.

Last reviewed: December 2026. Agent file locations were checked against the Claude Code, Gemini CLI, Codex and Aider documentation or source at review time. Every template is tested with a real gitignore matcher (see Tests).

# Everything in one file
curl -fsSL https://raw.githubusercontent.com/Ralpberry-Labs/gitignore-ai/main/AI.gitignore >> .gitignore

# Or pick templates
git clone https://github.com/Ralpberry-Labs/gitignore-ai
python3 gitignore-ai/scripts/combine.py Python Secrets Jupyter Model-Weights > .gitignore

Table of Contents

Templates

File Covers
templates/Python.gitignore Bytecode, venvs, build output, tool caches (short Python base)
templates/Secrets.gitignore .env* (keeps .env.example), keys, cloud credentials, Kaggle token, Streamlit/Chainlit secrets
templates/Jupyter.gitignore .ipynb_checkpoints, JupyterLab virtual documents, marimo caches
templates/Data.gitignore Root data/ (keeps data/sample/, .gitkeep, README), Parquet/Arrow/NumPy, archives, audio/video
templates/Model-Weights.gitignore safetensors, PyTorch, GGUF, Keras/TF, ONNX, TensorRT, Core ML, pickles, checkpoint folders
templates/Experiment-Tracking.gitignore W&B, MLflow, TensorBoard, Lightning, Hydra, DVCLive, Aim, Neptune, HF Trainer output, Optuna DBs
templates/LLM-Apps.gitignore Chroma, FAISS, LanceDB, Qdrant, Milvus local data, LlamaIndex storage/, LangChain cache, Gradio
templates/AI-Agents.gitignore Personal/generated files of Claude Code, Gemini CLI, Aider, SpecStory
AI.gitignore All of the above, combined and de-duplicated
global/gitignore_global Machine-wide ignores (OS junk, personal agent files)
scripts/combine.py Build your own mix from the templates

Which Templates Do I Need?

Project Templates
Training models (PyTorch, JAX, TF) Python, Secrets, Jupyter, Data, Model-Weights, Experiment-Tracking
Fine-tuning LLMs with Hugging Face Same as above (Trainer output and checkpoint folders included)
RAG app / chatbot (LangChain, LlamaIndex) Python, Secrets, LLM-Apps, AI-Agents
Running local models (llama.cpp, Ollama imports) Model-Weights, Secrets
Data science notebooks Python, Secrets, Jupyter, Data
Any repo where people use AI coding agents AI-Agents (plus your language template)
Not sure AI.gitignore

JavaScript/TypeScript AI apps: combine Secrets, LLM-Apps and AI-Agents with a standard Node.js .gitignore (node_modules/, build output).

What Each Template Ignores (and Why)

Secrets

.env
.env.*
!.env.example
!.env.sample
!.env.template
*.pem
*.key
credentials.json
service-account*.json
kaggle.json
.streamlit/secrets.toml

AI projects collect API keys fast (model providers, vector databases, tracing tools). The ! lines re-include example files so new contributors know which variables to set. Keep real values in a secret manager, your CI’s secret store, or untracked .env files.

Model weights

Checkpoints are large binary files that change on every run. Git stores every version forever, so one committed 2 GB checkpoint makes every future clone 2 GB larger even after you delete it.

Pattern Produced by
*.safetensors Hugging Face models, diffusion models, LoRA adapters
*.pt, *.pth, *.ckpt PyTorch, Lightning checkpoints
*.bin Older Hugging Face weights (pytorch_model.bin), OpenVINO
*.gguf, *.ggml llama.cpp and tools built on it
*.h5, *.keras, *.tflite, saved_model/ TensorFlow / Keras
*.onnx, *.engine, *.trt, *.plan ONNX, TensorRT
*.mlmodel, *.mlpackage/ Core ML
*.joblib, *.pkl, *.pickle scikit-learn and pickled objects
/checkpoints/, checkpoint-*/, /models/* Common output folders

Root-anchored patterns (/models/*) keep code packages such as src/app/models/ tracked. *.bin is broad: if you need a small binary fixture, re-include it with !tests/fixtures/thing.bin.

Data

The template ignores the root data/ folder but keeps data/README.md, data/.gitkeep and data/sample/ so the repo documents the data and ships a tiny sample for tests. Large formats (*.parquet, *.arrow, *.npy, archives, audio/video) are ignored anywhere; comment those lines out if you keep small fixtures in those formats.

Experiment tracking

Folder Tool
wandb/ Weights & Biases local run files
mlruns/, mlartifacts/ MLflow local tracking store
/runs/ TensorBoard SummaryWriter default
lightning_logs/ PyTorch Lightning default logger
/outputs/, /multirun/ Hydra run directories
dvclive/ DVCLive
.aim/, .neptune/ Aim, Neptune offline data
/trainer_output/, /tmp_trainer/ Hugging Face Trainer default output folders (newer / older versions)

LLM apps

Local vector stores (/chroma/, *.faiss, /lancedb/, /qdrant_storage/), LlamaIndex’s default persist folder /storage/, LangChain’s default SQLite cache .langchain.db, prompt-eval output, and Gradio’s .gradio/ folder. These are rebuilt from your documents and code; commit the ingestion script, not the index.

AI Coding Agents: Commit vs Ignore

Agent tools write two kinds of files into a repo. Shared configuration makes every teammate’s agent behave the same and belongs in git. Personal or generated files (local overrides, chat history, caches, worktrees) do not. The AI-Agents template ignores only the second kind.

Tool Commit (shared) Ignore (personal / generated)
Claude Code CLAUDE.md, .claude/settings.json, .claude/skills/, .claude/agents/, .claude/commands/, .claude/rules/, .mcp.json, .worktreeinclude .claude/settings.local.json, CLAUDE.local.md, .claude/worktrees/
Gemini CLI GEMINI.md, .gemini/settings.json, .geminiignore .gemini/.env, .gemini/worktrees/
OpenAI Codex AGENTS.md, .codex/config.toml (project config, used only in trusted projects) Personal settings live in ~/.codex/, outside the repo
Cursor .cursor/rules/, .cursorignore, .cursor/mcp.json if it has no secrets Personal settings live in the editor profile
GitHub Copilot .github/copilot-instructions.md, .github/instructions/  
Aider .aider.conf.yml, .aiderignore (if you want shared settings) .aider.chat.history.md, .aider.input.history, .aider.llm.history, .aider.tags.cache.v*/
SpecStory Optional: share saved chats on purpose .specstory/ by default
Any agent AGENTS.md (read by many tools) Scratch folders you create for agents

Notes from the tools’ docs:

Design Rules

  1. Ignore outputs, not inputs. Code, configs, prompts, small samples and docs stay tracked; anything a script can regenerate is ignored.
  2. Anchor directory names that are also common code names (/models/, /data/, /storage/, /outputs/, /runs/) so src/app/models/ is never hidden.
  3. Never hide shared agent config. Only personal and generated agent files are listed.
  4. Re-include examples. .env.example, data/sample/, models/README.md stay visible.
  5. Every pattern is tested with paths that must be ignored and paths that must stay tracked.

Where Big Files Should Go Instead

Option Good for Notes
Hugging Face Hub Models and datasets you share Versioned repos with large-file storage, model cards
Git LFS Medium binaries that must live next to code Hosting providers meter LFS storage and bandwidth
DVC Datasets and models versioned with git commits, stored in S3/GCS/Azure/SSH Writes small .dvc pointer files you commit; it creates its own .dvc/.gitignore
Experiment trackers (W&B Artifacts, MLflow Model Registry) Checkpoints tied to runs Lineage and metrics with each model
Object storage (S3, GCS, R2) Raw data, large archives Store the download script in git

I Already Committed It: Fixes

Adding a pattern does not untrack files git already tracks. Remove them from the index (the files stay on disk):

git rm -r --cached wandb/ model.safetensors .env
git commit -m "Stop tracking generated files"

Untrack everything that the new .gitignore now matches:

git rm -r --cached .
git add .
git status          # review before committing
git commit -m "Apply .gitignore"

The big file is still in history and in every clone. To shrink the repo you must rewrite history with git-filter-repo, then force-push and have everyone re-clone:

git filter-repo --path checkpoints/ --invert-paths     # remove a folder from all history
git filter-repo --strip-blobs-bigger-than 50M          # remove all large blobs

Rewriting history is disruptive: coordinate with your team first. Hosting providers may also cache old objects; check their docs for removing sensitive data.

Leaked an API Key? Do This Now

  1. Revoke or rotate the key at the provider immediately. Assume it is compromised the moment it was pushed; automated scanners find public keys within minutes.
  2. Check the provider’s usage dashboard for unexpected activity and set spending limits.
  3. Remove the key from the code and from history (see above); rewriting history does not un-leak it, which is why step 1 comes first.
  4. Turn on secret scanning and push protection in your git host, and add a pre-commit secret scanner such as Gitleaks or TruffleHog.

Global gitignore for AI Developers

Some files are personal to you in every repo. Put them in your global excludes file instead of every project:

mkdir -p ~/.config/git
cp global/gitignore_global ~/.config/git/ignore
git config --global core.excludesFile ~/.config/git/ignore
git config --global --get core.excludesFile     # verify

Git reads ~/.config/git/ignore by default when core.excludesFile is unset, so the git config line is only needed if you keep the file elsewhere. Per-repo personal ignores that you never want to commit go in .git/info/exclude.

.gitignore controls git. AI tools have their own ignore files that control what the model can read:

File Tool Effect
.cursorignore Cursor Hide files from AI features and indexing
.geminiignore Gemini CLI Exclude files from Gemini CLI tools
.aiderignore Aider Exclude files from Aider’s repo map and edits
.aiexclude Gemini Code Assist Exclude files from context
.dockerignore Docker Keep .env, weights and data out of images
Claude Code permissions.deny (Read(./.env)) Claude Code Block reads of specific files via settings

Most agents also skip gitignored files during search, which is another reason to ignore generated data and secrets.

gitignore Syntax Cheat Sheet

Pattern Matches
*.pt Any .pt file at any depth
wandb/ A directory named wandb at any depth (and everything inside)
/models/ models/ only at the repo root
data/* Contents of root data/ (a slash in the middle anchors to the .gitignore location)
**/logs logs at any depth
logs/**/*.json JSON files anywhere under logs/
!keep.txt Re-include a previously ignored path
\#file / \!file Literal # or ! at the start
# comment Comment line

The most common surprise: you cannot re-include a file if its parent directory is ignored. That is why the Data template uses /data/* (ignore the contents) instead of /data/ (ignore the folder) before !/data/sample/.

Debugging: Why Is This File Ignored?

git check-ignore -v path/to/file            # prints the .gitignore file, line and pattern
git check-ignore -v --no-index path         # also for tracked files
git status --ignored                        # list ignored files
git ls-files --others --ignored --exclude-standard   # same, script-friendly
git ls-files -ci --exclude-standard         # tracked files that are now ignored

Tests

uv run --with pathspec python -m unittest discover -s tests

tests/test_templates.py parses each template with pathspec’s GitIgnoreSpec (which follows git’s rules, including negation) and checks lists of paths that must be ignored and paths that must stay tracked, for example src/app/models/user.py, .claude/settings.json, .env.example and data/sample/tiny.csv. It also checks that AI.gitignore matches the output of combine.py --all and that no template has duplicate patterns or trailing whitespace. All tests pass as of December 2026.

FAQ

Should I commit Jupyter notebooks? Yes, the notebooks themselves are source. Ignore checkpoints. To keep diffs small, strip outputs with a pre-commit hook such as nbstripout, or pair notebooks with scripts using Jupytext.

Should I commit uv.lock, poetry.lock or requirements.txt? Yes. Lockfiles make training environments reproducible. They are not ignored by any template here.

Should .env.example be committed? Yes, with placeholder values. The Secrets template re-includes it.

Should I commit CLAUDE.md, AGENTS.md or .cursor/rules? Yes. They are shared instructions that make every teammate’s agent follow the same conventions. Only local overrides are ignored.

Is .mcp.json safe to commit? Yes if it contains no secrets. Reference environment variables for keys instead of pasting values.

Why not just ignore *.json or *.csv? Configs, schemas, eval sets and small fixtures are often JSON or CSV and must be tracked. The templates ignore folders and formats that are almost always generated or large.

My models/ folder is Python code. Will it be ignored? Not unless it is at the repository root. Only /models/* (root) is ignored, and src/.../models/ stays tracked; the tests check this. If your root models/ is code, delete that line.

Does this replace a full Python .gitignore? No. Python.gitignore here is a short base. For a complete Python list, combine a full Python template with the AI templates.

How do I keep a few weights in git on purpose? Add negations at the end of your .gitignore, for example !tests/fixtures/tiny-model.safetensors, or track them with Git LFS.

Where do Hugging Face downloads go? By default to ~/.cache/huggingface (outside the repo). If you set HF_HOME to a folder inside the project, add that folder to .gitignore.

Where to Go Next

  1. Read the official gitignore documentation; the pattern rules are short and precise.
  2. Set up the global excludes file once on each machine.
  3. Add secret scanning to pre-commit (Gitleaks) and notebook output stripping (nbstripout).
  4. Move datasets and checkpoints to DVC or the Hugging Face Hub and commit only pointers and download scripts.
  5. Write an AGENTS.md or CLAUDE.md for your repo so coding agents know your conventions, and commit it.

Contributing

PRs welcome, especially for new AI tools and frameworks. Every new pattern needs test paths in tests/test_templates.py (at least one path it must ignore and one similar path it must not), a source showing where the tool writes the file, and a regenerated AI.gitignore (python3 scripts/combine.py --all > AI.gitignore). Keep entries accurate: do not ignore files a tool expects teams to share.

License

MIT. See LICENSE.

If this helped you, a star helps others find it.

More free resources

Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.