Git Bisect for Vibe Coders: Find the Prompt That Broke It

Git bisect finds the commit that broke your app by cutting the history in half, over and over. You tell it one commit that worked and one that is broken, it checks out the middle, you say “good” or “bad”, and it repeats. With 100 commits that takes about seven checks, not a hundred.
If you committed after each prompt, the commit it lands on is the prompt that broke it. It only works if you made those commits.
Before you start
- Do you have commits? Run
git log --oneline. If you see one per prompt or per feature, good. If you see three giant ones, or nothing, bisect can only point at a giant commit. - Is your tree clean?
git statusshould say nothing to commit. If not, rungit stash -unow. After the bisect, rungit bisect resetfirst andgit stash popsecond; popping onto an old commit conflicts. - Mac, Linux, or Windows with Git Bash or WSL. The scripts below use
sh. You need git 2.28 or newer and Node 18 or newer.
Using Lovable or Bolt? Both can sync a project to a GitHub repository (Lovable Git sync docs, Bolt GitHub docs). Clone that repository and run git log --oneline. If it shows commits, everything below works on it. Their built-in version history is a different feature, and this post does not cover it.
The commands you will paste:
git bisect startgit bisect bad HEADgit bisect good <a commit that worked>git bisect run sh ../check.shgit bisect reset # always, to get back to your branchWhen do I need this?
When the thing used to work and you do not know what changed. Say the cart total was right on Monday, you have sent the AI eleven prompts since (a nav bar, discount codes, dark mode, a search box), and today the total ignores quantities. Reading eleven diffs is slow. Asking the AI “what broke it?” gets a guess. Bisect gets an answer.
For two or three commits, just read the diffs. Bisect pays off from about ten.
A demo you can run
This script builds a throwaway repo called shop with eleven commits, one per prompt. One of those commits quietly breaks the cart. Save it as setup.sh:
#!/bin/sh# usage: sh setup.sh [late]set -erm -rf shop && mkdir -p shop/src && cd shopc() { git add -A && git commit -qm "$1"; }GOOD='function total(items) { return items.reduce((s, i) => s + i.price * i.qty, 0); }'BAD='function total(items) { return items.reduce((s, i) => s + i.price, 0); }'
echo "$GOODmodule.exports = { total };" > src/cart.jsc "prompt 1: cart total"echo "// formatting" > src/format.js; c "prompt 2: dollar formatting"echo "// nav" > src/nav.js; c "prompt 3: add nav bar"echo "// discounts" > src/discount.js; c "prompt 4: discount codes"echo "// footer" > src/footer.js; c "prompt 5: footer links"if [ "$1" = "late" ]; then echo "// profile page" > src/profile.js; c "prompt 6: profile page"else echo "$BADmodule.exports = { total };" > src/cart.js c "prompt 6: wire discount into cart"fiecho "// dark mode" > src/theme.js; c "prompt 7: dark mode"echo "const x = ;" > src/search.js; c "prompt 8: half-finished search box (does not run)"if [ "$1" = "late" ]; then echo "$BADmodule.exports = { total };" > src/cart.jsfiecho "// search ok" > src/search.js; c "prompt 9: finish search"echo "// settings" > src/settings.js; c "prompt 10: settings page"echo "// avatar" > src/avatar.js; c "prompt 11: avatars"git log --onelineRun sh setup.sh. You now have a repo where the cart is broken at the latest commit and nobody knows which prompt did it.
What is the check?
Bisect needs a yes-or-no test it can run at every step. Write down what the user sees: “three items at $19.99 plus one at $5.00 should total 6497 cents.” That is a behavior check, not a test of how the code is built, so it keeps working no matter how the AI restructures things. Save this next to the repo (not inside it, because bisect swaps files in and out as it moves through history) as check.sh:
#!/bin/sh# Run from inside the repo. Exit 0 = good, 1 = bad, 125 = cannot test this commit.if [ -f src/search.js ]; then node -e "require('./src/search.js')" 2>/dev/null || exit 125finode -e "const { total } = require('./src/cart');const t = total([{ price: 1999, qty: 3 }, { price: 500, qty: 1 }]);process.exit(t === 6497 ? 0 : 1);"Git’s docs say exit 0 means good, 1 to 127 (except 125) means bad, and 125 means “cannot test this commit, skip it”. The script skips (125) only for something unrelated to the behavior under test, here the half-finished search box. If the file under test, cart.js, fails to load, the check says bad on purpose: a file the AI broke so badly it does not load is often the bug. In a test of this, skipping that case left git unable to name the culprit; marking it bad found the commit.
If your app has dependencies, the old commit’s node_modules is whatever you installed last, not what that commit needed. Add [ -f package-lock.json ] && { npm ci --silent || exit 125; } as the first line of the check. This line was run in a scratch repo with one local file: dependency, where bisect named the right commit. Installs from the npm registry were not tested, so try it on your own repo at a known-good commit first.
Confirm the check fails on the broken tip and passes on the good end before you trust it:
cd shopsh ../check.sh; echo "exit=$?" # expect exit=1git checkout -q $(git rev-list --max-parents=0 HEAD)sh ../check.sh; echo "exit=$?" # expect exit=0git checkout -q mainA check that has not been seen failing, and passing, proves nothing. A wrong answer from it sends bisect down the wrong half without a warning.
Run the bisect
git bisect startgit bisect bad HEADgit bisect good $(git rev-list --max-parents=0 HEAD) # the very first commitgit bisect run sh ../check.shThe third line uses the first commit as “good” because here we know the cart worked at prompt 1. In your own repo, use the last commit or tag you remember working. Output (hashes will differ on your machine):
...4f6be482abf06f4829133e689638c6324dcac7e7 is the first bad commit prompt 6: wire discount into cart src/cart.js | 2 +-Eleven commits, a handful of checks, one culprit (the exact count printed varies a little by git version; this run used 2.34.1): the discount prompt rewrote the total and dropped the quantity. Now look at what that prompt changed. In the diff, lines starting with - were removed and lines with + were added. Use the hash bisect printed, not the one below:
git show 4f6be48 -- src/cart.jsgit bisect reset # always: puts you back on your branchWant a record? Run git bisect log > bisect.log before the reset. If you later find the check was wrong, git bisect replay bisect.log replays your steps so you can change one (both commands were run for this post and work). To undo the bad commit instead of fixing it by hand, git revert <hash> adds a new commit that reverses it. Or paste the diff to the AI and ask it to explain that one change; a single diff is small enough to trust.
Then fix it and run the same check again. In the demo, put * i.qty back in src/cart.js:
sh ../check.sh; echo "exit=$?" # exit=0 once the quantity is counted againSkipping git bisect reset leaves you on an old commit.
What if a commit in the middle does not run?
Half-finished prompts leave the app unrunnable. Build the other history with sh setup.sh late, where the cart breaks in prompt 9 right after prompt 8, the half-finished search box. Run the same bisect. Real output:
There are only 'skip'ped commits left to test.The first bad commit could be any of:20da7b4b43a43d1a2cf61f41979ad95e6b8854c4462233beadca4173c254164f618ef7da1085e599The two hashes are prompts 8 and 9. Prompt 8 never ran, so git cannot tell them apart. It cut eleven commits to two; read both diffs. Other git versions may list more candidates, so start with the earliest one listed after the last good commit. This is the best argument for committing only when the app runs.
What does this need from me?
One habit: commit after every prompt that worked, with the prompt in the message. git add -A && git commit -m "prompt 6: wire discount into cart" takes five seconds. One huge commit per day, or none, leaves nothing to bisect. The git habits post covers the routine.
Two limits. Bisect finds the commit that changed the behavior, not the wrong line (git show is for that). And it assumes the bug was introduced once and that your check behaves the same way across history. If the bug appeared, vanished and came back, or the check is flaky, the answer can mislead.
Can I make the AI do it?
Yes, and you can hand it the check:
Something that worked in commit
<good hash>is broken at HEAD: the cart total should be 6497 cents for these items, and it is not. Write a shell script that exits 0 when this is right and 1 when it is wrong, and 125 only if something unrelated to the cart does not run (if the cart code itself fails to load, that counts as 1). Save it outside the repo. Then rungit bisect runwith it between that good commit and HEAD, tell me the first bad commit, and show me its diff. Do not change any code. Rungit bisect resetat the end.
Read the script before it runs. A check that checks the wrong thing makes bisect confidently wrong, and you will not notice until the diff makes no sense.
Once you know the commit, the next step is a test that fails on it and keeps it from coming back: Your AI fixed one bug and broke two shows how.
The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.