git checkout with uncommitted changes causes silent data loss
Resolved 💬 6 comments Opened Mar 26, 2026 by lastdomovoi Closed May 3, 2026
Problem
Claude Code performs git checkout <branch> on its own initiative (e.g., to switch to a feature branch for committing) while there are uncommitted changes in the working directory. Modified files are silently overwritten by the target branch's version, causing loss of work.
Steps to reproduce
- User makes changes to files on branch A (doesn't commit yet)
- Claude Code decides on its own to switch to branch B (e.g., for organizing commits)
- Claude runs
git checkout B— files from branch B overwrite local changes - Changes from step 1 are lost without warning
Expected behavior
Claude Code should NEVER run git checkout when there are uncommitted changes. It should either:
- Commit changes first (even as a WIP commit)
- Refuse to switch branches and warn the user about uncommitted changes
- Use
git worktreefor parallel work
The user did not ask to switch branches — Claude Code made this decision autonomously and destroyed work in the process.
Impact
Lost ~30 minutes of work (CSS changes, template edits across 8 files) that had to be manually recreated.
Environment
- Claude Code CLI
- macOS
- git 2.x
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗