jesseduffield / jesseduffield/lazygit
Deleting branches fails with "fatal: bad revision 'xxx'" until lazygit restart
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
### Describe the bug
I was deleting some old local branches when suddenly the operation stopped working for any subsequent branches until I restarted lazygit.
Investigating further, it turns out this was due to one of the deleted branches being master/main (I accidentally had created both).
After deleting one of them, `self.c.Model().MainBranches` is not updated and still thinks both exist. All subsequent deletes go through `ConfirmLocalDelete` -> `allBranchesMerged` -> `IsBranchMerged` where it will fail the `rev-list` and stop any further processing. Restarting lazygit fixes this since `MainBranches` will be repopulated with the correct values.
### To Reproduce
Steps to reproduce the behavior:
```bash
git init -b master
git commit --allow-empty -m "Test"
git branch main
git branch dev
lazygit
```
1. Delete branch main, succeeds
2. Delete branch dev, fails
Opposite delete order succeeds.
### Expected behavior
Deletes should not fail.
I think one potential approach to fix this could be on `IsBranchMerged` error, call some new function that retriggers `determineMainBranches`, and then retry the branch merge check again (if it fails a second time, bail). These errors should be very infrequent but if they do happen, a refresh+retry should most likely fix it. Bonus is it will handle branches being deleted outside of lazygit.
### Screenshots
### Version info:
commit=80223c7fbbd0b86631a988834cbe88e267bb0bd9, build date=2025-11-01T09:43:19Z, build source=binaryRelease, version=0.56.0, os=windows, arch=amd64, git version=2.46.0.windows.1
### Terminal info:
Windows Terminal
### Additional context
Add any other context about the problem here.
> [!NOTE]
> Please try updating to the latest version or [manually building](https://github.com/jesseduffield/lazygit/#manual) the latest `master` to see if the issue still occurs.
Contributor guide
Assessment
This issue has not been assessed yet.