Skip to main content

gitree: git-aware project tree printing and zipping for docs and LLMs

Project description

gitree ๐ŸŒด

A git-aware CLI tool to provide LLM context for coding projects by combining project files into a single file with a number of different formats to choose from.


GitHub stars PyPI GitHub forks Contributors Issues closed PRs closed


โœจ Features

Feature Description
๐Ÿ“Š Project Tree Visualization Generate clean directory trees with customizable depth and formatting
๐Ÿ—œ๏ธ Smart Zipping Create project archives that automatically respect .gitignore rules
๐ŸŽฏ Flexible Filtering Control what's shown with custom ignore patterns, depth limits, and item caps
๐Ÿ” Gitignore Integration Use .gitignore files at any depth level, or disable entirely when needed
๐Ÿ“‹ Multiple Export Formats Export to files, copy to clipboard, or display with emoji icons
๐Ÿ“ Directory-Only View Show just the folder structure without files for high-level overviews
๐Ÿ“ˆ Project Summary Display file and folder counts at each directory level with summary mode

๐Ÿ”ฅ The problems it solves:

  • sharing project structure in issues or pull requests
  • generating directory trees for documentation
  • pasting project layouts into LLMs
  • converting entire codebases to a single json file using .gitignore for prompting LLMs.

๐Ÿ“ฆ Installation

Install using pip (python package manager):

# Install the latest version using pip
pip install gitree

# Get the stable version instead (older, lacks features)
pip install gitree==0.1.3

๐Ÿ’ก Usage

To use this tool, refer to this format:

gitree [path] [other CLI args/flags]

Open a terminal in any project and run:

# path should default to .
gitree

Example output:

Gitree
โ”œโ”€ gitree/
โ”‚  โ”œโ”€ constants/
โ”‚  โ”‚  โ”œโ”€ __init__.py
โ”‚  โ”‚  โ””โ”€ constant.py
โ”‚  โ”œโ”€ services/
โ”‚  โ”‚  โ”œโ”€ __init__.py
โ”‚  โ”‚  โ”œโ”€ draw_tree.py
โ”‚  โ”‚  โ”œโ”€ list_enteries.py
โ”‚  โ”‚  โ”œโ”€ parser.py
โ”‚  โ”‚  โ””โ”€ zip_project.py
โ”‚  โ”œโ”€ utilities/
โ”‚  โ”‚  โ”œโ”€ __init__.py
โ”‚  โ”‚  โ”œโ”€ gitignore.py
โ”‚  โ”‚  โ””โ”€ utils.py
โ”‚  โ”œโ”€ __init__.py
โ”‚  โ””โ”€ main.py
โ”œโ”€ CODE_OF_CONDUCT.md
โ”œโ”€ CONTRIBUTING.md
โ”œโ”€ LICENSE
โ”œโ”€ pyproject.toml
โ”œโ”€ README.md
โ”œโ”€ requirements.txt
โ””โ”€ SECURITY.md

Using emojis as file/directory icons:

gitree --emoji

Example output:

Gitree
โ”œโ”€ ๐Ÿ“‚ gitree/
โ”‚  โ”œโ”€ ๐Ÿ“‚ constants/
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ __init__.py
โ”‚  โ”‚  โ””โ”€ ๐Ÿ“„ constant.py
โ”‚  โ”œโ”€ ๐Ÿ“‚ services/
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ __init__.py
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ draw_tree.py
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ list_enteries.py
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ parser.py
โ”‚  โ”‚  โ””โ”€ ๐Ÿ“„ zip_project.py
โ”‚  โ”œโ”€ ๐Ÿ“‚ utilities/
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ __init__.py
โ”‚  โ”‚  โ”œโ”€ ๐Ÿ“„ gitignore.py
โ”‚  โ”‚  โ””โ”€ ๐Ÿ“„ utils.py
โ”‚  โ”œโ”€ ๐Ÿ“„ __init__.py
โ”‚  โ””โ”€ ๐Ÿ“„ main.py
โ”œโ”€ ๐Ÿ“„ CODE_OF_CONDUCT.md
โ”œโ”€ ๐Ÿ“„ CONTRIBUTING.md
โ”œโ”€ ๐Ÿ“„ LICENSE
โ”œโ”€ ๐Ÿ“„ pyproject.toml
โ”œโ”€ ๐Ÿ“„ README.md
โ”œโ”€ ๐Ÿ“„ requirements.txt
โ””โ”€ ๐Ÿ“„ SECURITY.md

For zipping a directory:

gitree --zip out

creates out.zip in the same directory.

For combining interactive selection with export:

gitree --export project -i

This allows you to interactively select files and save the export to project.txt.


๐Ÿงญ Interactive Mode

Gitree supports an interactive mode that allows you to select files and directories step-by-step instead of relying only on CLI flags.

[!TIP] > This is useful when:

  • you want fine-grained control over included files
  • you prefer a guided terminal-based selection flow
  • you want to explore a project before exporting its structure

Enable Interactive Mode

Use the -i or --interactive flag:

gitree --interactive
# or
gitree -i

How It Works

When interactive mode is enabled, Gitree will:

  1. Scan the project directory (respecting .gitignore)
  2. Present an interactive file and folder selection menu
  3. Allow you to choose what to include or exclude
  4. Generate output based on your selections

Interactive Controls

During interactive selection, the following keys are supported:

  • โ†‘ / โ†“ โ€” navigate items
  • Space โ€” select / deselect item
  • Enter โ€” confirm selection
  • Esc / Ctrl+C โ€” exit interactive mode

Example

gitree -i --emoji --out context.txt

This will:

  • launch interactive selection
  • display output using emojis
  • save the result to context.txt

Updating Gitree:

To update the tool, type:

pip install -U gitree

Pip will automatically replace the older version with the latest release.


๐Ÿงช Continuous Integration (CI)

Gitree uses Continuous Integration (CI) to ensure code quality and prevent regressions on every change.

What CI Does

  • Runs automated checks on every pull request
  • Verifies that all CLI arguments work as expected
  • Ensures the tool behaves consistently across updates

Current Test Coverage

Test Type Description
CLI Argument Tests Validates all supported CLI flags and options
Workflow Checks Ensures PRs follow required checks before merging

[!NOTE] CI tests are continuously expanding as new features are added.


Implementation details

The CI configuration is defined in .github/workflows/

Each workflow file specifies:

  • Trigger conditions (i.e. pull request)
  • The Python version(s) used
  • The commands executed during the pipeline

If any step fails, the pipeline will fail and the pull request cannot be merged until the issue is resolved.

โš™๏ธ CLI Arguments

In addition to the directory path, the following options are available:

Basic CLI flags

Argument Description
--version, -v Displays the installed version.
--interactive, -i Interactive selection UI.
--init-config Create a default config.json in the current directory.
--config-user Open config.json in the default editor.
--no-config Ignore config.json and use hardcoded defaults.

Input/Output flags

Argument Description
--max-depth Limit recursion depth (e.g., --max-depth 1).
--hidden-items Include hidden files and directories (does not override .gitignore).
--exclude [pattern] Exclude patterns (e.g., --exclude *.pyc __pycache__).
--exclude-depth [n] Limit depth for exclude patterns (e.g., --exclude-depth 2).
--gitignore-depth [n] Control discovery depth for .gitignore (e.g., --gitignore-depth 0).
--no-gitignore Ignore all .gitignore rules.
--max-items Limit items per directory (default: 20).
--max-entries Limit entries (default: 40).
--no-max-entries Disable total entries limit.
--no-files Show only directories (hide files).
--emoji, -e Use emojis in output.
--summary Print file/folder counts per level.
--include [pattern] Include patterns (often used with interactive mode).
--include-file-type Include a specific file type (e.g., .py, json).
--include-file-types Include multiple file types (e.g., png jpg json).

Listing flags

Argument Description
--max-depth Limit recursion depth (e.g., --max-depth 1).
--hidden-items Include hidden files and directories (does not override .gitignore).
--exclude [pattern] Exclude patterns (e.g., --exclude *.pyc __pycache__).
--exclude-depth [n] Limit depth for exclude patterns (e.g., --exclude-depth 2).
--gitignore-depth [n] Control discovery depth for .gitignore (e.g., --gitignore-depth 0).
--no-gitignore Ignore all .gitignore rules.
--max-items Limit items per directory (default: 20).
--no-max-items Remove per-directory item limit.
--no-files Show only directories (hide files).

๐Ÿ“ File Contents in Exports

When using --json, --tree, or --md flags, file contents are included by default. This feature:

  • โœ… Includes text file contents (up to 1MB per file)
  • โœ… Detects and marks binary files as [binary file]
  • โœ… Handles large files by marking them as [file too large: X.XXmb]
  • โœ… Uses syntax highlighting in Markdown format based on file extension
  • โœ… Works with all filtering options (--exclude, --include, .gitignore, etc.)

To export only the tree structure without file contents, use the --no-contents flag:

gitree --json output.json --no-contents

Installation (for Contributors)

Clone the repository:

git clone [https://github.com/ShahzaibAhmad05/Gitree](https://github.com/ShahzaibAhmad05/Gitree)

Move into the project directory:

cd Gitree

Setup a Virtual Environment (to avoid package conflicts):

python -m venv .venv

Activate the virtual environment:

.venv/Scripts/Activate      # on windows
.venv/bin/activate          # on linux/macOS

[!WARNING] If you get an execution policy error on windows, run this: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Install dependencies in the virtual environment:

pip install -r requirements.txt

The tool is now available as a Python CLI in your virtual environment.

For running the tool, type (venv should be activated):

gitree

For running unit tests after making changes:

python -m tests

Contributions

[!TIP] This is YOUR tool. Issues and pull requests are welcome.

Gitree is kept intentionally small and readable, so contributions that preserve simplicity are especially appreciated.

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

gitree-0.4.0.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

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

gitree-0.4.0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file gitree-0.4.0.tar.gz.

File metadata

  • Download URL: gitree-0.4.0.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitree-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5a12f8d459c3a07eaa34d23dfeb969f150043bb104e5f31bfbabed5603f6c6ea
MD5 a4aa0a998b51800c818d260cf6cec50a
BLAKE2b-256 770603e57052c84c394fe27001fdbe179ff2fdcc368189b8ec8336616d63ac10

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitree-0.4.0.tar.gz:

Publisher: workflow.yml on ShahzaibAhmad05/gitree

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

File details

Details for the file gitree-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: gitree-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitree-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ae931035fe20e4f3956b275e1d44e617e0cd0d882d10f1a4795eb46cc5bb61a
MD5 13efa0f110141e385546dc30758b26f7
BLAKE2b-256 890915279ac8680d9c670b7ecf2c6a9f8c7ac15e5f18e8f090c49f974b7acdb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitree-0.4.0-py3-none-any.whl:

Publisher: workflow.yml on ShahzaibAhmad05/gitree

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