Skip to main content

git-nearest

A compact Git graph of the branches closest to HEAD or another commit. Run git nearest for a quick view of the neighborhood, or git nearest -i to explore it in your terminal.

git nearest showing the graph of a local branch and nearby remote-tracking branches
as text
$ git nearest
@  ae22273d  HEAD -> fix-typo  [1 staged, 1 untracked]
~  (1)
○  574e9395  origin/main  [nearest]
├─╮
~ │  (3)
│ │ ○  2cf4c0c2  origin/release/1.2
├─┼─╯
○ │  fc1afa3b  merge-base
~ │  (1)
│ ○  51eef8f5  origin/feature/login
│ ~  (2)
├─╯
○  5a42fea0  merge-base
~ (n) = n commits folded between

@ marks the view center. The graph highlights the nearest branch tips and keeps merge-bases visible. A row such as ~ (3) folds three commits that you can expand as needed. The working tree note next to HEAD shows whether there are staged, modified, untracked or conflicted files.

The example is generated from a synthetic repository. Demo script

Install

Needs Python 3.8+ and git. No other dependencies.

uv tool install git-nearest      # or: pipx install git-nearest

The package installs an executable called git-nearest; git runs any git-<name> on your PATH as git <name>.

Usage

git nearest [N] [-b REV] [--match REGEX] [--expand REV]... [--details REV] [-i]
            [--no-status] [--color {auto,always,never}] [--no-color] [--version]
N number of distinct branch tip commits to show (default 5)
-b, --branch REV center the view on this branch or commit (default HEAD)
--match REGEX select branches by a regular expression on their full ref names
--expand REV show the commits in the fold below REV (repeatable)
--details REV show the commit subject, author, time, SHA, and parents for REV
-i, --interactive explore the graph with the keyboard
--no-status skip the working tree check (it runs git status, which can be slow on huge repositories)
--color auto (default) colors only on a terminal and respects NO_COLOR
--version print the version and exit

By default, the candidates are all remote-tracking branches. With --match, the pattern is searched against the full ref names of local and remote-tracking branches. The filter applies before selecting the nearest tips. Branches that point to the same commit share one place in the result.

git nearest --match '^refs/remotes/origin/(main$|release/)'
git nearest --match '^refs/heads/'
git nearest -b origin/main --expand origin/main --details origin/main

Interactive mode

Run git nearest -i in a terminal. The initial view comes from the same options as command mode. Use the keys below to change that view. Quitting prints the final graph into your terminal scrollback.

Key Action
↑ / ↓ or k / j Select a commit or fold
Enter Center the view on the selected commit
g Jump to a branch or commit
f Edit the branch regex filter
n Edit the number of distinct tips to show
Backspace Return to the previous view
Home Return to the checked-out HEAD
Space Expand or collapse the selected fold
i Toggle details for the selected commit
q Quit and leave the final graph in the terminal

Centering the view is a read-only operation. Press Esc to cancel a prompt or Ctrl+U to clear its input. Use the command-line options to render the same view directly from the shell.

How it works

Git records ancestry through commits. The closest tip is the one that leaves the fewest commits exclusive to the view center, then the fewest commits exclusive to the tip. A branch that has absorbed the center's history through a merge can rank above the branch it originally split from. The graph shows newest commits first while keeping children above their parents. Fold counts show how many commits are hidden in that section of the graph.

Remote-tracking branches come from your local repository. Run git fetch to update them. If no branches match, the graph still shows the view center.

Similar tools

  • Scripts based on git show-branch or on grepping git log --decorate for origin/ (the usual Stack Overflow answers) look only at the first decorated ancestor, so they miss ties.
  • Git Town records a parent for each branch when it creates the branch. That is exact but only works for branches it knows about; git-nearest infers from history and needs no setup.

Development

uv run pytest

License

MIT

Metadata

Release files for git-nearest 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-nearest 0.3.0
File Size Uploaded Provenance Actions
git_nearest-0.3.0.tar.gz 18.9 kB Without provenance Details for git_nearest-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for git-nearest 0.3.0
File Interpreter ABI Platform Actions
git_nearest-0.3.0-py3-none-any.whl Python 3 none any Details for git_nearest-0.3.0-py3-none-any.whl

Total release size: 35.8 kB

Release files / git_nearest-0.3.0.tar.gz

Download URL git_nearest-0.3.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a78142038c641cf839fc85875f0db040958861f5f51b31a32d23765cd85c41d9
BLAKE2b-256 checksum
How to use checksums
c66a2925d3fb7c818a15c3e9862d8177be00093a873265a0b6dcce6b629afc2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / git_nearest-0.3.0-py3-none-any.whl

Download URL git_nearest-0.3.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbbff3d5552b39a0652bc84f8ef6b6b8e652a2ebba702a1bd18a7b3241925ea9
BLAKE2b-256 checksum
How to use checksums
e56d790044aedfb759a1d701d72a2356bb84006485a5d385a4b4fc7e8deb0683
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for git-nearest 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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