How to fix You need to fix your working tree before running bisect in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 144 views

This error occurs when you have uncommitted changes in your working directory and try to run git bisect. Git bisect needs to checkout different commits during the binary search process, and local modifications would conflict with these checkouts.

Quick fix

Fixes You need to fix your working tree before running bisect

git status
  1. Check the status of your working tree
  2. Stash your changes (recommended)
  3. Start the bisect session
  4. End bisect and restore your changes
git โ€” error
git status
You need to fix your working tree before running bisect

What this error means

Git bisect is a powerful debugging tool that uses binary search to find the commit that introduced a bug. When you run `git bisect start`, Git needs to checkout different commits between a known "good" and "bad" state to narrow down the problematic commit. The "fix your working tree" error appears because Git cannot safely checkout other commits when you have uncommitted changes. These changes would either be lost during the checkout or cause conflicts. This is a safety mechanism to protect your work. The working tree refers to your actual files on disk as opposed to what's stored in Git's database. When it's "dirty" (has uncommitted changes), Git prevents operations that would overwrite or lose those changes.

Typical symptoms

  • Git bisect start fails immediately with 'fix your working tree' message
  • Cannot begin bisect session despite having good/bad commits identified
  • Error mentions 'Your local changes would be overwritten by checkout'
  • Bisect works in other clones of the same repository but not your current one
  • The error appears after running git bisect start or git bisect good/bad

Common causes

  1. You have modified files that haven't been staged or committed (most common)
  2. There are staged changes (git add) that haven't been committed yet
  3. Untracked files exist that would be overwritten by commits being tested
  4. A merge or rebase operation is in progress
  5. Previous bisect session wasn't properly cleaned up with git bisect reset
  6. File system changes from IDE auto-save or build tools modified tracked files

How to fix "You need to fix your working tree before running bisect"

1Check the status of your working tree

First, see exactly what changes are preventing bisect:

bash
git status

This shows:
- Changes not staged for commit: Modified tracked files
- Changes to be committed: Staged changes waiting for commit
- Untracked files: New files Git doesn't know about

Identify which category your changes fall into before proceeding.

2Stash your changes (recommended)

The safest option is to stash your changes, which saves them temporarily:

bash
git stash push -m "WIP: changes before bisect"

This saves both staged and unstaged changes. After bisect completes, restore them:

bash
git stash pop

Include untracked files if needed:

bash
git stash push -u -m "WIP: all changes before bisect"

The -u flag includes untracked files in the stash.

3Start the bisect session

Now that your working tree is clean, begin bisecting:

bash
git bisect start
git bisect bad HEAD              # Current commit has the bug
git bisect good <known-good-commit>  # Replace with a commit hash or tag

Git will checkout a commit halfway between good and bad. Test it, then mark:

bash
git bisect good   # If this commit doesn't have the bug
# OR
git bisect bad    # If this commit has the bug

Repeat until Git identifies the first bad commit.

4End bisect and restore your changes

When bisect finds the problematic commit, it displays the result. End the session:

bash
git bisect reset

This returns your repository to the branch you were on before bisecting. Now restore your stashed changes:

bash
git stash pop

If you have multiple stashes, list them first:

bash
git stash list
git stash pop stash@{0}  # Apply specific stash
5Alternative: Commit changes to a temporary branch

If your changes are substantial, commit them to a temporary branch instead of stashing:

bash
git checkout -b temp-work-branch
git add .
git commit -m "WIP: temporary commit for bisect"
git checkout main  # or your original branch

After bisecting:

bash
git checkout temp-work-branch
git reset HEAD~1   # Undo the commit, keep changes
git checkout main
git branch -D temp-work-branch  # Clean up
6Alternative: Use git worktree for non-disruptive bisect

If you don't want to interrupt your current work at all, create a separate working directory:

bash
git worktree add ../bisect-worktree HEAD
cd ../bisect-worktree
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>

This creates a linked working tree where you can bisect independently. Your main working directory remains untouched.

Clean up after bisecting:

bash
cd ..
rm -rf bisect-worktree
git worktree prune
7Handle a stuck bisect session

If a previous bisect session wasn't cleaned up properly:

bash
git bisect reset

If that fails, manually remove bisect state:

bash
rm -rf .git/BISECT_*
git checkout <your-branch>

Then stash/commit your changes and start fresh.

Advanced notes

### Automating Bisect with Scripts

For complex tests, automate bisect with a script:

bash
git bisect start HEAD <good-commit>
git bisect run ./test-script.sh

Your script should return:
- Exit code 0: Commit is good
- Exit code 1-127 (except 125): Commit is bad
- Exit code 125: Skip this commit (can't test)

### Handling Modifications During Bisect

If your test requires applying patches or modifications to each commit:

bash
git bisect run sh -c 'patch -p1 < ../fix.patch && make && make test; ret=$?; git reset --hard; exit $ret'

The git reset --hard undoes the patch before moving to the next commit.

### Git Worktree Benefits

Using git worktree for bisect has several advantages:
- Continue working in your main directory
- No need to stash or commit changes
- Bisect refs are isolated per worktree
- Can run bisect in the background

### Bisect with Path Limiting

If the bug is likely in specific files, limit bisect's scope:

bash
git bisect start -- src/auth/

Git will only consider commits that touched files in src/auth/.

### Preserving Bisect State

If you need to pause bisecting, the state is preserved. You can see where you are:

bash
git bisect log

To replay a bisect session from a log:

bash
git bisect replay bisect.log

Frequently asked questions

What does "You need to fix your working tree before running bisect" mean?
Git bisect is a powerful debugging tool that uses binary search to find the commit that introduced a bug. When you run git bisect start, Git needs to checkout different commits between a known "good" and "bad" state to narrow down the problematic commit. The "fix your working tree" error appears because Git cannot safely checkout other commits when you have uncommitted changes.
How do I fix "You need to fix your working tree before running bisect"?
This error occurs when you have uncommitted changes in your working directory and try to run git bisect. Git bisect needs to checkout different commits during the binary search process, and local modifications would conflict with these checkouts.
What causes "You need to fix your working tree before running bisect"?
You have modified files that haven't been staged or committed (most common) There are staged changes (git add) that haven't been committed yet Untracked files exist that would be overwritten by commits being tested
Is the "You need to fix your working tree before running bisect" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading