shellstreak

Move uncommitted changes to a new branch

Safe: nothing is lost

Short answer

Run git stash, then git switch -c <new-branch>, then git stash pop. Your unfinished changes move to the new branch.

The commands, one by one

  1. 1git stash

    Puts your unfinished edits aside and leaves the files clean.

  2. 2git switch -c brunch

    Creates the branch brunch and switches to it.

  3. 3git stash pop

    Brings your edits back here and removes them from the stash.

For your own repository: Uncommitted changes actually follow you when you switch, so git switch -c brunch alone often works. The stash route also works when switching would refuse.

Try it safely

You edited bread.txt on main, but it's for a new brunch menu.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 63, The stash, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.