{
    "slug": "git_bisect",
    "term": "Git Bisect",
    "category": "git",
    "difficulty": "intermediate",
    "short": "A binary search tool that finds the commit that introduced a bug by marking commits as good or bad — locating the culprit in O(log n) steps.",
    "long": "git bisect automates a binary search through commit history. You mark a known-good commit and a known-bad commit, then git checks out the midpoint. You test and mark it good or bad, halving the search space each time. For 1000 commits, this finds the culprit in ~10 steps. With git bisect run, you automate the test — bisect runs your test suite and marks commits automatically, making regression hunting fully automated.",
    "aliases": [
        "git binary search",
        "bisect"
    ],
    "tags": [
        "git",
        "debugging",
        "version-control"
    ],
    "misconception": "You need to know programming history to use git bisect — you only need a reproducible test; git bisect run handles the rest automatically.",
    "why_it_matters": "Without bisect, finding a regression in 500 commits requires manual investigation; bisect finds it in 9 steps — transforming hours of debugging into minutes.",
    "common_mistakes": [
        "Not having a reproducible test before starting bisect — manual marking requires re-testing at each step.",
        "Marking a commit as bad when it has an unrelated test failure — poisons the search.",
        "Not running git bisect reset after finishing — leaves the repo in detached HEAD state.",
        "Not using git bisect run with an automated test — missing the most powerful feature."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "git_rebase_vs_merge",
        "git_blame_history",
        "regression_testing"
    ],
    "prerequisites": [
        "git_workflows_compared",
        "unit_testing",
        "continuous_integration"
    ],
    "refs": [
        "https://git-scm.com/docs/git-bisect"
    ],
    "bad_code": "# Manual bisect — slow without automation:\ngit bisect start\ngit bisect bad HEAD\ngit bisect good v1.2.0\n# Git checks out commit — developer manually runs app and marks\ngit bisect bad  # or good\n# Repeat 10 times manually...",
    "good_code": "# Automated bisect with test script:\ngit bisect start\ngit bisect bad HEAD\ngit bisect good v1.2.0\n\n# test.sh exits 0 = good, non-zero = bad:\ngit bisect run ./test.sh\n# Git runs binary search automatically — finds the commit\ngit bisect reset  # Return to original HEAD",
    "quick_fix": "Run git bisect start, mark the current broken commit as bad and a known good commit as good, then git bisect run vendor/bin/phpunit to automate finding the regression",
    "severity": "info",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/git_bisect",
        "html_url": "https://codeclaritylab.com/glossary/git_bisect",
        "json_url": "https://codeclaritylab.com/glossary/git_bisect.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Git Bisect](https://codeclaritylab.com/glossary/git_bisect) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/git_bisect"
            }
        }
    }
}