Convert Git repository contents to Markdown format.
Project description
git2md
A command-line tool for converting Git repository contents to Markdown format. This tool generates a Markdown file containing the repository's directory tree and the contents of its files. It supports various file types, including Python scripts, Markdown files, Jupyter Notebooks, and PDFs.
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.
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 source
-
Clone the repository:
git clone https://github.com/xpos587/git2md.git cd git2md
-
Run the installation script:
python install.py
The script will:
- Install the package in your Python environment.
- Create a symlink in
/usr/local/bin
for global access (requiressudo
).
Usage
Basic Command
git2md <path> [options]
Options
Option | Description |
---|---|
path |
Path to the Git project directory or file to process. |
-o , --output |
Output file path for saving the generated Markdown. |
-rex , --regex-exclude |
List of regular expressions to exclude specific 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/directories using regex
git2md /path/to/repo -rex ".*\.log$" ".*\.tmp$" -o output.md
Skip empty files and copy output to clipboard
git2md /path/to/repo -se -cp
Ignore .gitignore
rules
git2md /path/to/repo -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.1.tar.gz
.
File metadata
- Download URL: git2md-1.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df14b84069fcc40e8fe7a7ee21491d9cda617fd92391941fd5dc4d149861a158 |
|
MD5 | 968c356593457452a9ac5e7898daa2b9 |
|
BLAKE2b-256 | a215a3c16ad568ad9d3710c306426d81dc9cb3d5f786e549656d8b61ac841146 |
Provenance
The following attestation bundles were made for git2md-1.1.1.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.1.tar.gz
- Subject digest:
df14b84069fcc40e8fe7a7ee21491d9cda617fd92391941fd5dc4d149861a158
- Sigstore transparency entry: 151057046
- Sigstore integration time:
- Predicate type:
File details
Details for the file git2md-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: git2md-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 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 | e7838859b55f6772786018db5ecb2bcda4429c83c4a43ecfa2e571e525790b8b |
|
MD5 | adb87384b59ff28c6e3aa251dc201513 |
|
BLAKE2b-256 | 8d13e0e245b5376ae46e1564698ed7ad4bc909e10c755547a059140161a9e95a |
Provenance
The following attestation bundles were made for git2md-1.1.1-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.1-py3-none-any.whl
- Subject digest:
e7838859b55f6772786018db5ecb2bcda4429c83c4a43ecfa2e571e525790b8b
- Sigstore transparency entry: 151057047
- Sigstore integration time:
- Predicate type: