A Python script that exports an entire git repository into a single, well-organized markdown file. Perfect for sharing codebases with LLMs, creating documentation snapshots, or archiving project states.
- Git-aware: Only includes tracked files, automatically respecting
.gitignore - Customizable filtering: Use
.repotomdrcto exclude or include specific files - Visual directory tree: Shows folder structure with intuitive icons
- Table of contents: Clickable links with line ranges for quick navigation
- Syntax highlighting: Code blocks use appropriate language tags based on file extensions
- Binary detection: Automatically skips binary files with a placeholder note
- Zero dependencies: Uses only Python standard library + git
# Clone the repository
git clone https://github.com/MathiasMahn/GitRepo2Markdown-Exporter.git
cd GitRepo2Markdown-Exporter
# Make the script executable (optional)
chmod +x repo2markdown.pyRequirements:
- Python 3.10+
- Git installed and available in PATH
python repo2markdown.py [repo_path] [output_file]| Argument | Default | Description |
|---|---|---|
repo_path |
. (current directory) |
Path to the git repository |
output_file |
repo_contents.md |
Output markdown filename |
# Export current directory
python repo2markdown.py
# Export a specific repository
python repo2markdown.py /path/to/my-project
# Export with custom output filename
python repo2markdown.py ./my-project project-snapshot.mdCreate a .repotomdrc file in your repository root to customize which files are included in the output.
[exclude]
# Patterns for files to exclude (in addition to .gitignore)
# These files won't appear in the markdown output
[include]
# Patterns for files to include (overrides .gitignore)
# Use this to add gitignored files to the outputPatterns follow gitignore-style matching:
| Pattern | Matches |
|---|---|
*.log |
All .log files in any directory |
docs/* |
All files directly in the docs/ folder |
docs/** |
All files anywhere under docs/ |
test_*.py |
Files starting with test_ ending in .py |
config/?.json |
Single character matches like config/a.json |
[abc].txt |
Matches a.txt, b.txt, or c.txt |
[exclude]
# Don't include test files in documentation
tests/*
*_test.py
*.spec.js
# Exclude build artifacts that might be tracked
dist/*
build/*
# Exclude sensitive configs
.env
secrets.json
config/local.yaml
[include]
# Include example env file even though .env* is gitignored
.env.example
# Include sample configs
*.sample
config/*.example.yaml- The
.repotomdrcfile itself is automatically excluded from output [include]patterns can pull in gitignored files[exclude]patterns only affect git-tracked files- Patterns are applied in order: tracked files → minus excludes → plus includes
The generated markdown file contains:
- Header — Repository name, path, and file count
- Directory Structure — Visual tree of all folders and files
- Table of Contents — Links to each file with line ranges
- File Contents — Full source code with syntax highlighting
# Repository: my-project
**Path:** `/home/user/my-project`
**Total tracked files:** 12
---
## 📂 Directory Structure
\```
my-project/
├── 📄 README.md
├── 📁 src/
│ ├── 📄 main.py
│ └── 📄 utils.py
└── 📁 tests/
└── 📄 test_main.py
\```
## 📑 Table of Contents
| File | Lines | Type |
|------|-------|------|
| 📄 [README.md](#readme-md) | 25-40 | text |
| 📄 [src/main.py](#src-main-py) | 41-85 | text |
...
## 📄 File Contents
### src/main.py
**Path:** `src/main.py`
\```py
def main():
print("Hello, World!")
\```- LLM Context: Feed entire codebases to AI assistants in a single file
- Code Reviews: Share a complete project snapshot for review
- Documentation: Generate a browsable archive of your codebase
- Onboarding: Help new team members understand project structure
- Archival: Create point-in-time snapshots of repositories
- Runs
git ls-filesto get all tracked files (respects.gitignore) - Builds a nested directory tree structure
- Calculates line ranges by pre-computing content lengths
- Generates the final markdown with TOC, tree view, and file contents
- Requires the target directory to be a git repository
- Binary files are detected and skipped (placeholder shown instead)
- Very large repositories may produce unwieldy output files
- Line range links work best in markdown viewers that support anchor links
MIT License — feel free to use, modify, and distribute.
Contributions are welcome! Feel free to open issues or submit pull requests.