Skip to main content

Convert Git repository contents to Markdown format

Project description

๐Ÿ”„ git2md

PyPI Python Version Build Status License AUR version

๐Ÿš€ A powerful command-line tool for converting Git repository contents into Markdown format. This tool is perfect for developers and documentation specialists who need to create structured Markdown files based on repository contents, including directory trees and file contents.

Read README in Russian here


โœจ Features

  • ๐ŸŒณ Repository Directory Tree Generation: outputs repository structure in tree block format.
  • ๐Ÿ“ File to Markdown Conversion:
    • Supports syntax highlighting for code files.
    • Converts Jupyter Notebook (.ipynb) and PDF (.pdf) to Markdown.
  • ๐ŸŽฏ Support for .gitignore, .globalignore and .mdignore for local projects:
    • Automatically excludes files/directories specified in .gitignore, .globalignore or .mdignore.
  • ๐Ÿ” Custom Exclusion Patterns: use regular expressions to exclude specific files or directories.
  • ๐Ÿ—‘๏ธ Skip Empty Files: ignores files without content.
  • ๐Ÿ“‹ Copy Results to Clipboard: simplifies using generated Markdown.

๐ŸŽฌ Demonstration

Below is a demonstration of how git2md works:

Demo of git2md


๐Ÿ“‹ Requirements

  • ๐Ÿ Python 3.9 or newer
  • ๐Ÿง Linux Operating System Now supports Windows, MacOS, Linux (X11 and Wayland)
  • ๐Ÿ“ฆ Dependencies:
    • pathspec (for .gitignore, .mdignore, .globalignore support)
    • nbconvert (for Jupyter Notebook conversion) (support temporarily limited)
    • PyMuPDF4LLM (for PDF conversion) (support discontinued, will be replaced with better alternatives)
    • wl-copy/xsel/xclip (optional, Linux-only for clipboard functionality)

๐Ÿ“ฅ Installation

๐Ÿ“ฆ Install via PyPI

You can install git2md directly through PyPI using pip:

pip install git2md

๐Ÿ—๏ธ Install via AUR (Arch Linux)

For Arch Linux users, the package is available in AUR as python-git2md. It can be installed using AUR helpers like paru or yay:

paru -S python-git2md

๐Ÿ”จ Install from Source

  1. Clone the repository:

    git clone https://github.com/xpos587/git2md.git
    cd git2md
    
  2. Build and install:

    python setup.py build
    pip install .
    

๐Ÿš€ Usage

๐Ÿ’ป Basic Command

git2md [path] [options]

If path is not specified, the current directory will be used.

โš™๏ธ Options

Option Description
path Path to project directory or Git file (default: current folder)
-o, --output Path to save generated Markdown
-c, --copy Copy result to clipboard
--ignore List of patterns to exclude files or directories

๐Ÿ“ Examples

๐Ÿ“‚ Generate Markdown for Entire Repository

git2md /path/to/repo -o output.md

๐Ÿ” Exclude Specific Files Using Patterns

git2md --ignore "./assets/style-*.css" "*.log" "*.tmp" -o output.md

๐Ÿ—‘๏ธ Copy Result to Clipboard

git2md --copy

๐Ÿ“„ Output Format

๐ŸŒณ Directory Tree

The directory tree is included as a code block with 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 in the header, followed by its contents in a code block.

๐Ÿ Example for Python File (main.py)

# File: src/main.py

```
print("Hello, world!")
```

# End of file: src/main.py

๐Ÿ““ Example for Jupyter Notebook (notebook.ipynb)

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 PDF (document.pdf)

Text is extracted in Markdown format:

# File: document.pdf

# Extracted content from PDF...

# End of file: document.pdf

๐Ÿ”ง Global Exclusion Patterns

You can create a .mdignore file in the same directory as the script to specify patterns that should be excluded for all repositories. The format is identical to .gitignore.

๐Ÿ“ Example .mdignore

__pycache__/
*.pyc
.mypy_cache/
.env
*.log

๐Ÿ‘จโ€๐Ÿ’ป Development

To set up the development environment:

  1. Create a virtual environment:

    micromamba create -p ./.micromamba/ -f environment.yml
    micromamba activate -p ./.micromamba/
    
  2. Install the project in development mode:

    pip install -e .
    

๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


๐Ÿค Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Create a Pull Request.

๐Ÿ‘ฅ Authors

Michael (x30827pos@gmail.com)


๐Ÿ™ Acknowledgments

Thanks to the developers of repomix and git2txt.

The idea emerged from the need for universal and simplified repository documentation 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

git2md-1.1.4.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

git2md-1.1.4-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file git2md-1.1.4.tar.gz.

File metadata

  • Download URL: git2md-1.1.4.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for git2md-1.1.4.tar.gz
Algorithm Hash digest
SHA256 269862559ff7e779dedc3c67f69b45a09888a913943204597919cd080176269f
MD5 73fd16474803f0c4f1cb8fab203b407a
BLAKE2b-256 8ad869737422b7f524dc1fe80ac0e6cf61e0b8f4f94448299085126a4fa83094

See more details on using hashes here.

Provenance

The following attestation bundles were made for git2md-1.1.4.tar.gz:

Publisher: release.yaml on Xpos587/git2md

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

File details

Details for the file git2md-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: git2md-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for git2md-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cfd02b5c311ee25a81382e95c37d08174e321c04b9502198294f1bb69171585e
MD5 d72b208ad8a38c7fdb95afdd32d43f3c
BLAKE2b-256 416d92d8a01190b1024dffedc846785f1ba9a52f849e826af81b8472e5381b4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for git2md-1.1.4-py3-none-any.whl:

Publisher: release.yaml on Xpos587/git2md

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