dev@local: ~/project — git
dev@local~/project$git checkout feature-branch
Updating a1b2c3d..d4e5f6g
error: local changes overwritten by checkout
Please commit your changes or stash them before you switch branches.
Aborting
Diagnostics Translation
Git prevented a branch switch because it would overwrite unsaved changes in your working directory.
waiting for resolution...
MediumVersion Control System

Reviewed for reference consistency: April 11, 2026

Data Loss Risk

HIGH RISK

Git stopped to prevent overriding unsaved work. Do not force commands without stashing or committing first.

What To Know

This state usually means the target branch needs to rewrite a file you already changed locally, so Git halts the branch switch before it touches disk.

Where Did It Fail?

Working Tree
Your local files
add
Staging Index
Prepared changes
commit
Local Repo
Commit history
push/fetch
Remote Server
GitHub/GitLab
Git halted to protect the uncommitted files in your active working directory.

Commands That Trigger This

$git checkout feature-branch
Running or `git switch feature-branch` with unsaved edits in `main.js`
$git checkout
Accidentally typing when you meant to create a new branch

Technical Background

01

This is one of Git's primary safety features. Uncommitted changes exist only on your local disk.

02

Git only blocks the checkout if the target branch differs from your current branch for the modified files. If the file is identical in both branches, Git allows the checkout and carries your uncommitted changes over.

Underlying Causes

Switching branches when the target branch has a different version of a file you are currently editing
Attempting to checkout a branch while halfway through an unfinished merge
Having unstaged changes that directly conflict with the destination branch's commit tree

Frequently Asked Questions

Yes, if the changes do not conflict with the target branch. If they do conflict, Git forces you to commit or stash them first.

Related Git States