Skip to content
/ git2md Public

A command-line tool for converting Git repository contents to Markdown format. This tool helps you create documentation by generating a Markdown file containing the repository structure and the contents of all files.

License

Notifications You must be signed in to change notification settings

Xpos587/git2md

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ 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 ([email protected])


πŸ™ 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.

About

A command-line tool for converting Git repository contents to Markdown format. This tool helps you create documentation by generating a Markdown file containing the repository structure and the contents of all files.

Resources

License

Stars

Watchers

Forks