Skip to main content

ghdir

Download a single folder from a GitHub repo, without cloning the whole thing.

Point it at a GitHub tree URL and it grabs just that folder, keeping the directory structure intact. You should probably use git clone if you're downloading an entire repo, but this tool works for that as well.

Install

pip install ghdir

or with uv:

uv tool install ghdir

Needs Python 3.11+.

From source

git clone https://github.com/eko-071/ghdir.git
cd ghdir
uv tool install .

or with pip:

pip install .

Updating

pip install --upgrade ghdir

or:

uv tool upgrade ghdir

If you installed from a local checkout instead, pull and reinstall:

cd ghdir
git pull
uv tool install . --force

Usage

ghdir https://github.com/NVlabs/Eagle/tree/main/Embodied

This downloads everything under Embodied/ into a local Embodied/ folder.

A few flags if you need them:

  • -o, --output DIR — where to put the files (default: the folder's own name)
  • --branch NAME — use a different branch than the one in the URL
  • --dry-run — see the file count and total size without downloading anything
  • --workers N — number of concurrent downloads (default: 8)
  • --include GLOB — only download files matching this glob (repeatable)
  • --exclude GLOB — skip files matching this glob (repeatable)
  • --max-size SIZE — skip files larger than SIZE (e.g. 50M, 1.5G)
  • --force — re-download everything, even files that are already up to date
  • --version — print the installed version and exit

Some examples:

# whole repo, default branch
ghdir https://github.com/octo/hello

# a different branch than what's in the URL
ghdir https://github.com/octo/hello/tree/main/src --branch dev

# custom destination
ghdir https://github.com/octo/hello/tree/main/src -o ./vendor/hello-src

# just check what it would download
ghdir https://github.com/octo/hello/tree/main/src --dry-run

# only Python files, nothing over 50M
ghdir https://github.com/octo/hello/tree/main/src --include "*.py" --max-size 50M

Running it looks like this:

Found 132 files (1482974 bytes) in main/Embodied
Downloaded 132 files to Embodied

Already-up-to-date files are skipped on re-runs. Only missing or changed files are fetched. To force a fresh copy of everything, use --force:

Downloaded 0 files, skipped 132 already up to date, to Embodied

Authentication

By default ghdir hits the GitHub API anonymously (60 requests/hour) and cannot download from private repositories. Storing a token unlocks private repos and raises the limit to 5000 requests/hour:

ghdir auth login     # prompts for a token, or pass --token TOKEN inline
ghdir auth status    # show who you're logged in as
ghdir auth logout    # remove the stored token

Tokens are saved to ~/.config/ghdir/token (mode 0600). For CI or scripted use, set the GHDIR_TOKEN environment variable instead — it takes precedence over the stored file and needs no interactive prompt.

Shell completion

ghdir supports tab completion for bash, zsh, fish, and PowerShell:

ghdir --install-completion

This detects your shell and installs completion for flags (--branch, --include, etc.) and local directory paths for -o/--output. Restart your shell, or source your rc file, for it to take effect.

Developing

uv sync --extra dev           # install ghdir + dev deps
uv run pytest                 # unit tests, no network calls
uv run pytest -m integration  # live test against real GitHub repos
uv run ruff check src tests   # lint

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghdir-0.2.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

ghdir-0.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file ghdir-0.2.0.tar.gz.

File metadata

  • Download URL: ghdir-0.2.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ghdir-0.2.0.tar.gz
Algorithm Hash digest
SHA256 903b0e4bc804882c09c00bd056da601473ff73573ca770c63a0fa97b428c9cec
MD5 6535f09422fa52f5b9206e9d21af4e12
BLAKE2b-256 f2e8a7a5dbd4067c7bb9af46d9a6d6d03a4ee75b2d29a515513833aa2fd6508b

See more details on using hashes here.

File details

Details for the file ghdir-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ghdir-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ghdir-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8159bdc5b2668d005f84bdaac5bccc2e633be15f17d7f8155d3e3636fc1c62
MD5 72d72dbb60607b80bb20b9dce29ff3e2
BLAKE2b-256 f0a495110bab36e3a9d8cdf87e55a25ff266a0a10735cfbddf21a83f8a898083

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page