Safely Moving Uncommitted Changes to a New Branch in Git

2 min read

You’re working on something and realize you’re on the wrong branch — maybe you started coding on main when you should have created a feature branch first. This guide shows you how to move uncommitted changes to a new branch in Git without losing any work.

The examples here are run on WSL2 Ubuntu in Windows, but they work the same on any system with Git installed.

The Simple Way: Just Create a New Branch

If you’re moving your changes to a new branch (one that doesn’t exist yet), you don’t need git stash at all. Uncommitted changes — both staged and unstaged — automatically carry over when you create and switch to a new branch:

git switch -c feature-branch

That’s it. Your changes are now on feature-branch, and the original branch (main) is clean. You can verify with:

git status

You should see your modified files listed, now on the new branch. From here, stage and commit normally:

git add .
git commit -m "Add feature implementation"

This works because uncommitted changes live in your working directory, not on a branch. Switching branches just moves the branch pointer — your uncommitted files come with you.

Using Stash: Moving Changes to an Existing Branch

If the target branch already exists and has different commits, Git might block the switch because of conflicts. In this case, use git stash to temporarily save your changes, switch branches, and reapply them.

1. Stash your changes

git stash

This saves all uncommitted changes (staged and unstaged) and reverts your working directory to a clean state. For a more descriptive stash, add a message:

git stash push -m "login form validation work"

2. Switch to the target branch

git switch feature-branch

3. Reapply the stash

git stash pop
  • git stash pop — applies the stash and removes it from the stash list
  • git stash apply — applies the stash but keeps it in the list (useful if you might need it again)

If the stash conflicts with changes on the target branch, Git will mark the conflicting files. Resolve them the same way you’d resolve merge conflicts. For a walkthrough on handling conflicts, see How to Merge Branches in Git Without Auto-Resolving Conflicts.

Quick Reference

Scenario Commands
Move changes to a new branch git switch -c new-branch
Move changes to an existing branch git stash, git switch target-branch, git stash pop
Stash with a message git stash push -m "description"
View stash list git stash list
Apply a specific stash git stash apply stash@{2}
Drop a stash git stash drop stash@{0}

Conclusion

For new branches, git switch -c is all you need — no stashing required. For existing branches, the stash-switch-pop pattern keeps your changes safe during the transition.

If you need to switch branches while keeping uncommitted work in more complex scenarios, check out How to Switch to a Different Branch in Git Including the Uncommitted Changes.