All fixes

Help, I can't switch branches because of my local changes

Git will not switch while your uncommitted work would be lost. Put it aside, switch, and bring it back later.

What Git says~/my-app
git switch main
error: Your local changes to the following files would be overwritten by checkout:
	index.html
Please commit your changes or stash them before you switch branches.
Aborting

The fix

  1. git stash

    Puts your uncommitted changes on a shelf. The working tree is clean now.

  2. git switch main

    The switch works now.

  3. git switch feature/login

    Later, back on your own branch …

  4. git stash pop

    … take the changes off the shelf again.

main is an example. Replace it with your own.

Why this works

Switching branches rewrites your files, and Git refuses to do that when it would destroy edits that exist nowhere else. git stash moves those edits onto a shelf and leaves a clean working tree. Plain git stash only takes tracked files: if Git complains about untracked files instead, use git stash -u. Popping on a different branch can conflict; Git then keeps the stash, so nothing is lost.