Skip to main content

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

Project description

gitree ๐ŸŒด

A CLI tool that helps generate structured context for LLMs by combining project files into a single, exportable format.


GitHub stars PyPI GitHub forks Contributors Issues closed PRs closed


๐Ÿ“ฆ Installation

Install using pip (python package manager):

# Install the latest version using pip
pip install gitree

# to update gitree
pip install -U gitree

๐Ÿ’ก Usage

To use this tool, refer to this format:

gitree [paths] [other CLI args/flags]

To literally get started, I would recommend doing this:

Open a terminal in any project and run:

# paths should default to .
# This will scan gitignores by default
gitree

Now try this for better visuals:

gitree --emoji

You should see an output like this:

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

Some useful commands you can use everyday with this tool:

# Copy all C++ code in your project, 
# with interactive selection for those files
gitree **/*.cpp --copy -i
# Zip the whole project files (respecting gitignore)
# creates project.zip in the same directory
gitree --zip project
# Export the file contents of your project, in different formats to choose from
gitree --export project --format tree
gitree --export project --format json
gitree --export project --format md

๐Ÿงฉ How it Works

    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚           Start            โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
                  โ”‚
                  โ–ผ
    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚      Argument Parsing      โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
                  โ”‚
                  โ–ผ
    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚  Files/Folders Selection   โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
                  โ”‚
                  โ–ผ
    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚   Interactive Selection    โ”‚
    โ”‚      (only if used)        โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
            โ”‚
            โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚                         โ”‚
            โ–ผ                         โ–ผ
    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚ Zipping Service โ”‚    โ”‚   Drawing Service   โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
            โ”‚                  โ”‚
            โ”‚                  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚                  โ”‚                    โ”‚
            โ”‚                  โ–ผ                    โ–ผ
            โ”‚         โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
            โ”‚         โ”‚  Copy Service   โ”‚  โ”‚  Export Service  โ”‚
            โ”‚         โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ  โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
            โ”‚                  โ”‚                    โ”‚
            โ”‚                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚                             โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
               โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
               โ”‚    Output & Finish     โ”‚
               โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ



โœจ Overall Features

Feature Description
Tree Visualization Generate a structure for any directory for visualizing and understanding the codebase
Smart File Selection Control what's selected by the tool with custom ignore patterns, depth limits, and item caps
Interactive Selection Gain full control of the output by reviewing what's selected by the file selection service
Copy Your Codebase Instantly copy the whole codebase file contents to your clipboard to paste into LLMs
Multiple Export Formats Export your codebase contents to files using tree, json and markdown formats
Zipping the Whole Project Create project archives that automatically respect .gitignore rules
Large/Binary Files Handling Automatically detects binary and large files and marks or skips them during export

๐Ÿงช 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

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


โš™๏ธ CLI Arguments

The following optional arguments are available for use:

General Options

Argument Description
--version, -v Display the version number of the tool.
--config-user Create a default config.json file in the current directory and open that file in the default editor.
--no-config Ignore both user-level and global-level config.json and use default and CLI values for configuration.
--verbose Enable logger output to the console. Enabling this prints a log after the full workflow run. Helpful for debugging.

Output & Export Options

Argument Description
--zip, -z Create a zip archive of the given directory respecting gitignore rules.
--export Save project structure along with its contents to a file with the format specified using --format.
--format Format output only. Options: tree, json, md.

Listing Options

Argument Description
--max-items Limit items to be selected per directory.
--max-entries Limit entries (files/dirs) to be selected for the overall output.
--max-depth Maximum depth to traverse when selecting files.
--gitignore-depth Limit depth to look for during .gitignore processing.
--hidden-items Show hidden files and directories.
--exclude [pattern ...] Patterns of files to specifically exclude.
--exclude-depth Limit depth for exclude patterns.
--include [pattern ...] Patterns of files to specifically include.
--include-file-types Include files of certain types.
--copy, -c Copy file contents and project structure to clipboard. Similar to --export but copies to the clipboard instead.
--emoji, -e Show emojis in the output.
--interactive, -i Use interactive mode for further file selection.
--files-first Print files before directories.
--no-color Disable colored output.
--no-contents Don't include file contents in export/copy.
--no-contents-for [path ...] Exclude contents for specific files for export/copy.
--max-file-size Maximum file size in MB to include in exports (default: 1.0).
--override-files Override existing files.

Listing Override Options

Argument Description
--no-max-entries Disable --max-entries limit.
--no-max-items Disable --max-items limit.
--no-gitignore Do not use .gitignore rules.
--no-files Hide files (show only directories).


Installation (for Contributors)

Clone the repository:

git clone 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 always welcome.

Gitree is kept intentionally small and readable, so contributions that preserve simplicity and follow Contributing Guidelines 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.1.tar.gz (32.1 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.1-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gitree-0.4.1.tar.gz
  • Upload date:
  • Size: 32.1 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.1.tar.gz
Algorithm Hash digest
SHA256 eac211c03e669052d8fc00d67ca6fe9f4dad670087edcfe500c4345556cc164a
MD5 6b2441f12578e0382df1390d1c9570c6
BLAKE2b-256 dd7233ad53c4773ea5c05186c9a67403531b93b5b66b6d6c3be0d111e694fba8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitree-0.4.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: gitree-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 32.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f29c85bbf44a11b41bc631b4cd7560ea08bb6ef394cde14706157f32a954cd9d
MD5 5ef00ec2b2ce054fd2fcaf1d90fb6910
BLAKE2b-256 ec885cae04acdbbea0a02620d1e5de11b8193678c64957bc5ad1117ff3e51407

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitree-0.4.1-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