Skip to main content

AI-powered Git disaster recovery โ€” describe your git problem, get exact fix commands

Project description

๐Ÿ†˜ git-mistake

Describe your git disaster in plain English. Get exact fix commands instantly.

CI PyPI Python License: MIT

asciicast


Why

Git has ~150 commands and error messages designed by a kernel hacker in 2005. Every developer โ€” from interns to 10-year veterans โ€” eventually types the wrong thing and freezes. git-mistake reads your actual repo state, understands what went wrong, and tells you exactly what to run.

No Stack Overflow rabbit hole. No guessing. Just the fix.


Install

pip install git-mistake

Or run without installing:

pipx run git-mistake "your problem here"

Usage

# Describe your problem directly
git-mistake "I accidentally ran git reset --hard and lost my commits"
git-mistake "I committed to the wrong branch"
git-mistake "I have a merge conflict and I don't know how to resolve it"
git-mistake "I accidentally pushed my API key to GitHub"
git-mistake "I'm in a detached HEAD state"

# Interactive mode โ€” just run with no arguments
git-mistake

# Pattern matching only โ€” no AI, works fully offline
git-mistake --no-ai "I did git reset --hard"

# Dump your current git state (useful for bug reports)
git-mistake --context

How It Works

Your repo state              Your problem description
      โ”‚                               โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚  Pattern Matcher    โ”‚  โ† Covers ~80% of cases instantly, offline
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚ No match?
                   โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚  AI Engine          โ”‚  โ† Handles complex/unusual situations
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
         Exact fix commands + explanation

Stage 1 โ€” Offline pattern matching reads your git reflog, git status, and in-progress operation flags (merge, rebase, cherry-pick) to instantly resolve common disasters without any API call.

Stage 2 โ€” AI fallback kicks in for complex or unusual situations. Supports 3 providers โ€” set whichever key you have.


Covered Scenarios

Problem Severity
Accidental git reset --hard ๐Ÿ”ด High
Pushed secrets / credentials ๐Ÿ”ด High
Detached HEAD state ๐ŸŸก Medium
Merge conflict stuck ๐ŸŸก Medium
Rebase gone wrong ๐ŸŸก Medium
Accidentally deleted tracked files ๐ŸŸก Medium
Committed to wrong branch ๐ŸŸข Low
Untracked files / .gitignore issues ๐ŸŸข Low
Everything else AI fallback

AI Setup (Optional)

Works offline for common cases. For complex issues, set any one of these:

Provider Env Variable Get Key Free Tier
Anthropic Claude ANTHROPIC_API_KEY console.anthropic.com โ€”
OpenRouter OPENROUTER_API_KEY openrouter.ai/keys โœ… Yes
NVIDIA NIM NVIDIA_API_KEY build.nvidia.com โœ… Yes
# Set whichever you have โ€” only one needed
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENROUTER_API_KEY="sk-or-..."
export NVIDIA_API_KEY="nvapi-..."

# Make it permanent
echo 'export OPENROUTER_API_KEY="sk-or-..."' >> ~/.zshrc

# Override the default model
export OPENROUTER_MODEL="google/gemma-3-27b-it"
export NVIDIA_MODEL="meta/llama-3.3-70b-instruct"

OpenRouter and NVIDIA NIM both have free tiers โ€” no credit card needed.


Architecture

git-mistake/
โ”œโ”€โ”€ git_mistake/
โ”‚   โ”œโ”€โ”€ cli.py        # Entry point, argument parsing, orchestration
โ”‚   โ”œโ”€โ”€ context.py    # Reads all git state (reflog, status, flags)
โ”‚   โ”œโ”€โ”€ detector.py   # Fast offline pattern matching (~80% of cases)
โ”‚   โ”œโ”€โ”€ ai_helper.py  # Multi-provider AI fallback (Anthropic / OpenRouter / NVIDIA)
โ”‚   โ””โ”€โ”€ display.py    # Terminal colors and formatted output
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_detector.py   # 18 unit tests
โ”œโ”€โ”€ .github/workflows/ci.yml
โ””โ”€โ”€ pyproject.toml

Design decisions:

  • Zero dependencies โ€” stdlib only (subprocess, urllib, json). No requests, no rich, no click.
  • Offline-first โ€” pattern matching runs before any API call is made.
  • Context-aware โ€” reads actual .git/ state, not just your description.
  • Safe by default โ€” always suggests a backup branch before destructive commands.

Contributing

Bug reports with git-mistake --context output are incredibly useful. PRs adding new patterns to detector.py are always welcome.

git clone https://github.com/thalha-a9/git-mistake
cd git-mistake
pip install -e .
python -m pytest tests/ -v

License

MIT โ€” see LICENSE


Built for every developer who has typed git reset and immediately regretted it.

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

git_mistake-1.0.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

git_mistake-1.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file git_mistake-1.0.1.tar.gz.

File metadata

  • Download URL: git_mistake-1.0.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for git_mistake-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bb3c5405c0e93deacd19da1df50d717808744b8181c19228d0f3b7d494c339da
MD5 61569548b0ed106450a31a42b08cba71
BLAKE2b-256 a733755a98af098b73ab38a2021d7a0ddbb7cf1c39fa35898ced125b6ada8926

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_mistake-1.0.1.tar.gz:

Publisher: publish.yml on thalha-a9/git-mistake

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

File details

Details for the file git_mistake-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: git_mistake-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for git_mistake-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb2e044c973ace0452e2837d1bf962d6c3a1751a146427fe30ef851ab267ff52
MD5 e10e4559fac19de8dd581e674959c449
BLAKE2b-256 4a53363f778b2c3e6c9cafb9a0f28d47fe7beb2a9ab0a195a685d6c0c9740025

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_mistake-1.0.1-py3-none-any.whl:

Publisher: publish.yml on thalha-a9/git-mistake

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