Save unfinished work and switch branch
I must switch branches but my work is not ready to commit.
The problem
I must switch branches but my work is not ready to commit.
How the practice repository looked before
## main M notes.txt
01abb54 Add line two a89b8bd Add notes
The fix
Saved working directory and index state WIP on main: 01abb54 Add line two
stash@{0}: WIP on main: 01abb54 Add line twoOn branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: notes.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (b99492ccd838beb514afccfec947ff6e47a5bdd2)Check the result
M notes.txt
Why this works
git stash puts your uncommitted changes on a shelf and gives you a clean folder. git stash pop takes the newest shelf entry back and removes it from the list.
If this is not quite your case
Give a stash a name to find it later: git stash push -m "login form idea". git stash list shows them all; git stash apply puts changes back but keeps the entry, which is safer when you are not sure the pop will work. A pop can conflict if the branch changed in the same lines; Git then keeps the entry.
Be careful: A stash does not include untracked files unless you add -u.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.