The message “Please move or remove them before you switch branches” appears when Git refuses to change branches because untracked files in your working directory would be overwritten by files in the branch you are trying to switch to. Now, if Git switched branches immediately, your local file could be replaced or hidden, and you might not be able to recover it easily. And in plain terms, Git is protecting you from losing work. It has noticed that a file you have not committed—or a file Git is not tracking yet—has the same path as a file that exists in the target branch. The fix is usually simple: identify the conflicting files, then move them, remove them, stash them, or commit them before switching branches.
What the Message Actually Means
Git is designed to keep your working directory, staging area, and repository history consistent. When you run git switch or git checkout to change branches, Git compares the files in your current working directory with the files in the branch you want to enter. If a file exists in both places but is not tracked in your current branch, Git treats it as an untracked file. If that same path is tracked in the target branch, switching branches would cause a conflict Most people skip this — try not to. Practical, not theoretical..
The full error often looks like this:
error: The following untracked working tree files would be overwritten by checkout:
config/local.env
notes/todo.md
Please move or remove them before you switch branches.
Aborting
The key phrase is “untracked working tree files would be overwritten by checkout.Even so, ” Git is not saying your repository is broken. It is saying, “I cannot safely complete this branch switch without touching files that you have not committed Small thing, real impact..
This is different from the related message “Please commit your changes or stash them before you switch branches.” That message usually appears when you have modified tracked files. The “move or remove” version is more commonly associated with untracked files that collide with the target branch.
Why Git Refuses to Switch Branches
Git could technically overwrite the files, but doing so would be dangerous. Imagine you created a local configuration file, a draft document, or a temporary script. You have not committed it because it is personal, experimental, or environment-specific. Then you try to switch to a branch that already contains a tracked file at the same path. If Git silently replaced your file, your local work could disappear Most people skip this — try not to..
Easier said than done, but still worth knowing And that's really what it comes down to..
Git’s safety check prevents that scenario. The branch switch is aborted until you decide what should happen to the conflicting files. That decision depends on whether you need the files, whether they belong in the target branch, and whether you want to keep them temporarily.
Real talk — this step gets skipped all the time.
Step-by-Step Fix
Start by checking the current state of your repository:
git status
Look for the files listed in the error message. They will usually appear under “Untracked files” or “Changes not staged for commit.” Once you know exactly which files are causing the problem, choose one of the following solutions Nothing fancy..
Option 1: Move the Files Somewhere Safe
If you want to keep the files but do not need them in the current branch, move them outside the repository or into a backup folder. For example:
mkdir ../backup-local-files
mv config/local.env ../backup-local-files/
mv notes/todo.md ../backup-local-files/
Then try switching branches again:
git switch target-branch
After you switch, you can decide whether to copy the files back, adapt them to the new branch, or leave them in the backup folder. Moving files is the safest option when you are unsure whether you will need them later.
Quick note before moving on.
Option 2: Remove the Files
If the files are temporary, generated, or no longer needed, you can delete them. For a single file:
rm config/local.env
For a directory of generated files, be more careful. Preview what Git would remove with:
git clean -n
The -n flag performs a dry run. It shows what would be deleted without actually deleting anything. If the list is correct, remove untracked files with:
git clean -f
To remove a specific path only:
git clean -f config/local.env
Use git clean cautiously. It permanently deletes untracked files
without any undo option. This leads to there is no trash bin and no recovery through Git, because Git never tracked them in the first place. Double-check the dry-run output before you commit to the deletion.
Option 3: Stash the Changes
If the conflicting files are tracked and you simply want to set them aside temporarily, git stash is the cleanest approach:
git stash push -m "wip before switching branches"
This saves your modifications and restores a clean working tree, allowing the switch to proceed. When you return, restore your work with:
git stash pop
Stashing is ideal when you plan to come back to the changes soon and want them to stay inside the repository rather than being moved or deleted.
Option 4: Commit the Files
If the files are meaningful work that belongs in your current branch, commit them before switching:
git add config/local.env notes/todo.md
git commit -m "Add local config and draft notes"
Once committed, the working tree is clean and the branch switch will succeed without complaint. This is the right choice when the files represent real progress you do not want to lose or shuffle around.
Choosing the Right Option
The best solution depends on the value and purpose of the conflicting files:
- Keep them but out of the way → move them (Option 1).
- Temporary or generated junk → remove them (Option 2), after a dry run.
- Work in progress you will resume soon → stash it (Option 3).
- Real work that belongs in this branch → commit it (Option 4).
When in doubt, prefer the non-destructive options. Moving and stashing preserve your work, while deletion is irreversible.
Conclusion
The “local changes would be overwritten” error is not a failure but a safeguard. Git is protecting work that exists only on your machine. By running git status to identify the offending files and then choosing to move, remove, stash, or commit them, you resolve the conflict deliberately rather than losing anything by accident. Over time this check becomes second nature: you will instinctively keep your working tree clean before switching, and the error will rarely catch you off guard. Treat it as a prompt to make a conscious decision about your files, and branch switching will stay smooth and safe It's one of those things that adds up..