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.6.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.6-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: git2md-1.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 540f668b02bdad732a2dbe40171fdef115d28a319a3fc6926bee88ef663598b6
MD5 3bd2e6ca4958dd1923fba564bb1e15a4
BLAKE2b-256 954357605e7f9ebea05ad3a9da7610f961a1517d40cead183c36322a75869775

See more details on using hashes here.

Provenance

The following attestation bundles were made for git2md-1.1.6.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.6-py3-none-any.whl.

File metadata

  • Download URL: git2md-1.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c6071435f4b5f72a259ce9d5dd11d394057268acc20a0d01855db88fbad01fbb
MD5 e54a5d5e4b7cb51f3f1ceacc8595306c
BLAKE2b-256 dbd9b64a7bab1564ed082b622dc7c39c78e7c34dcd5d99c3ded42915973b192b

See more details on using hashes here.

Provenance

The following attestation bundles were made for git2md-1.1.6-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