How to move your changes to another Git branch without committing
You start coding and halfway through you notice you’re on the wrong branch, usually main. There’s no need to copy files around by hand.
If the branch already exists, stash the changes, switch and bring them back:
git stash
git checkout other-branch
git stash popIf the branch doesn’t exist yet it’s even simpler. Uncommitted changes come along when you create a branch, so you can skip stash entirely:
git switch -c my-new-branchgit stash pop may give you conflicts if the other branch changed the same files. Just resolve them like any other conflict. The stash isn’t dropped until it applies cleanly, so nothing gets lost, and git stash list will show it to you.