Skip to main content

Getting started

GitWhy has two interaction modes:
  • CLI — non-interactive output for scripting and piping
  • TUI — auto-opens an interactive terminal UI when stdout is a TTY

Command overview


git why setup

Set up GitWhy globally and configure coding-agent integrations.
Repository-local setup is deferred to the first git why save in each repository. That first save installs the post-commit hook, prepares .git/gitwhy/ local storage, saves repo-scoped credentials, and configures notes.rewriteRef. If you run git why setup inside a Git repository, GitWhy also registers that repository in your workspace. Flags: Examples:

git why save

Save structured context from stdin or a file.
Reads structured input from stdin or --file, injects metadata (context ID, commits), auto-categorizes, and stores the result under .git/gitwhy/contexts/. Accepts either XML format (preferred — wrap content in <context> tags) or Markdown format (legacy — use ## Section headings). Flags: Required fields (XML format): <title>, <story>, <reasoning> Required fields (Markdown format): ## Prompt, ## What Was Done, ## Reasoning Context ID, repository, branch, date, and commits are auto-populated in both formats. Examples:
Run git why save --help for full format guidance including all available XML tags and markdown sections.

git why get

Retrieve a saved context by ID.
Retrieves a saved context from the local repository store and prints the full markdown to stdout. Arguments: Examples:
If the context does not exist:

git why log

List all saved contexts.
In a TTY, opens the GitWhy TUI in the log view. In non-interactive output, prints a grouped plain-text list. Output:
If no contexts exist:

git why tree

Display the domain and topic context tree.
Like git why log, opens the TUI when stdout is a terminal. In non-interactive output, prints the tree in plain text. Output:

Search saved contexts using hybrid full-text search across local and cloud workspace contexts.
When a query is provided, prints ranked plain text results with scores, snippets, and file paths. Without a query, opens the interactive TUI with filter-as-you-type. Arguments: Flags: Output:
Examples:

git why push

Sync specific contexts to GitWhy cloud. Requires one or more context IDs.
By default, contexts are synced as private. Pass --share to publish them as team-visible. Flags: Output:
Examples:
Requires credentials. If none are available, the CLI exits with: missing API key. Run 'git why setup' first. Run git why log to see available context IDs.
Cloud verification (v0.6.7+): Before skipping a context, the CLI verifies it actually exists on the cloud — not just in the local push-state cache. This auto-heals most sync issues. Use --force only when even the cloud check doesn’t resolve the problem.

git why post-pr

Post context summary as a PR comment. Contexts are matched to the PR by verifying commit SHAs or branch name.
Without context IDs, auto-matches all local contexts against the PR’s commits. With IDs, filters to those and validates they belong to the PR. Flags: PR auto-detection: When no --pr or --branch is specified, GitWhy first checks the current branch for an open PR. If none is found, it scans all open PRs and matches them against branches in your saved contexts. This means you can run git why post-pr from main and it will find PRs for contexts saved on feature branches. Output:
Examples:
Requires the GitHub App installed on the repository, a GitWhy API key, and the GitHub CLI (gh) authenticated. Contexts are auto-synced and published before posting.

Help behavior

GitWhy uses Cobra help flags across all commands:
  • git why <command> -h — shows the command help
  • git why <command> --help — shows the command help
  • git why <command> -help — invalid (parsed as short flags)

See also