Convert Git repository contents to Markdown format.
Project description
git2md
A powerful command-line tool for converting Git repository contents into Markdown format. This tool is ideal for developers and documentation specialists who need to generate structured Markdown files from Git repositories, including directory trees and file contents.
Features
- Generate repository directory tree: Outputs the structure of the repository in a
tree
block format. - Convert files to Markdown:
- Supports syntax highlighting for code files.
- Converts Jupyter Notebooks (
.ipynb
) and PDFs (.pdf
) into Markdown.
- Support for
.gitignore
and.globalignore
:- Automatically excludes files/directories listed in
.gitignore
or.globalignore
.
- Automatically excludes files/directories listed in
- Custom exclusion patterns: Use regular expressions to exclude specific files or directories.
- Skip empty files: Avoids processing files with no content.
- Copy output to clipboard: Easily copy the generated Markdown output for further use.
- Multithreading support: Speeds up file processing for large repositories.
Demonstration
Add a demonstration GIF here to showcase how the tool works.
Requirements
- Python 3.12 or higher
- Linux operating system
- Dependencies:
pathspec
(for.gitignore
support)nbconvert
(for Jupyter Notebook conversion)PyMuPDF4LLM
(for PDF conversion)wl-copy
(optional, for clipboard functionality)
Installation
Install from PyPI
You can install git2md
directly from PyPI using pip:
pip install git2md
Install from AUR (Arch Linux)
For Arch Linux users, the package is available in the AUR as git2md-git
. You can install it using an AUR helper like paru
or yay
:
paru -S git2md-git
Install from source
-
Clone the repository:
git clone https://github.com/xpos587/git2md.git cd git2md
-
Build and install:
python setup.py build pip install .
Usage
Basic Command
git2md [path] [options]
Если путь не указан, будет использована текущая директория.
Options
Option | Description |
---|---|
path |
Path to the Git project directory or file (default: current directory) |
-o , --output |
Output file path for saving the generated Markdown |
-gexc , --glob-exclude |
List of glob patterns for excluding files or directories |
-se , --skip-empty-files |
Skip empty files during processing |
-cp , --clipboard |
Copy the output content to clipboard (requires wl-copy ) |
-igi , --ignore-gitignore |
Ignore .gitignore and .globalignore rules |
Examples
Generate Markdown for an entire repository
git2md /path/to/repo -o output.md
Exclude specific files using glob patterns
git2md -gexc "*.log" "*.tmp" -o output.md
Skip empty files and copy output to clipboard
git2md -se -cp
Ignore .gitignore
rules
git2md -igi -o output.md
Output Format
Directory Tree
The directory tree is included as a code block with the language identifier tree
. For example:
src/
├── main.py
├── utils/
│ ├── helper.py
│ └── __init__.py
└── README.md
File Contents
Each file is included with its relative path as a header, followed by its content in a code block.
Example for a Python File (main.py
)
# File: src/main.py
```python
print("Hello, world!")
```
# End of file: src/main.py
Example for a Jupyter Notebook (notebook.ipynb
)
The content is converted from .ipynb
to Markdown and included directly:
# File: notebook.ipynb
# Converted content from Jupyter Notebook...
# End of file: notebook.ipynb
Example for a PDF (document.pdf
)
The content is extracted as Markdown:
# File: document.pdf
# Extracted content from PDF...
# End of file: document.pdf
Global Ignore Patterns
You can create a .globalignore
file in the same directory as the script to specify patterns that should be ignored across all repositories. The format is identical to .gitignore
.
Example .globalignore
__pycache__/
*.pyc
.mypy_cache/
.env
*.log
Development
To set up the development environment:
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate
-
Install dependencies:
pip install pathspec nbconvert pymupdf4llm
-
Install in editable mode:
pip install -e .
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
- Fork the repository.
- Create your feature branch (
git checkout -b feature/amazing-feature
). - Commit your changes (
git commit -m 'Add some amazing feature'
). - Push to the branch (
git push origin feature/amazing-feature
). - Open a Pull Request.
Authors
Michael (x30827pos@gmail.com)
Acknowledgments
Thanks to the developers of the pathspec
, nbconvert
, and PyMuPDF4LLM
libraries.
Inspired by the need to easily document Git repositories for LLM-based workflows.
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
Built Distribution
File details
Details for the file git2md-1.1.3.tar.gz
.
File metadata
- Download URL: git2md-1.1.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02acfae4cb1408128028af8024a20726c7b313a69ecadb38889c712162fc93e0 |
|
MD5 | ed351f3c66bceaa14271e1a60fd86cd4 |
|
BLAKE2b-256 | 757c592f009b70f4d2bc6028d669144ece17d600f1d78913c81e95a6f7734bd0 |
Provenance
The following attestation bundles were made for git2md-1.1.3.tar.gz
:
Publisher:
release-python.yaml
on Xpos587/git2md
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
git2md-1.1.3.tar.gz
- Subject digest:
02acfae4cb1408128028af8024a20726c7b313a69ecadb38889c712162fc93e0
- Sigstore transparency entry: 151168464
- Sigstore integration time:
- Predicate type:
File details
Details for the file git2md-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: git2md-1.1.3-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05912eac52e7b86b23fff30e7dade88fa48d38c5fd54b1421598e2e745c86cad |
|
MD5 | 966d3d7c2af45c7c8f5538e04e31e535 |
|
BLAKE2b-256 | 24fc3d590bdb2da6df4d8abc72808dafcfcaa5dc87513eb001bcdec3d53f8b91 |
Provenance
The following attestation bundles were made for git2md-1.1.3-py3-none-any.whl
:
Publisher:
release-python.yaml
on Xpos587/git2md
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
git2md-1.1.3-py3-none-any.whl
- Subject digest:
05912eac52e7b86b23fff30e7dade88fa48d38c5fd54b1421598e2e745c86cad
- Sigstore transparency entry: 151168466
- Sigstore integration time:
- Predicate type: