Move uncomitted changes between Git branches
Sometimes I start working on a wrong branch of the project. But uncommitted changes can be moved.
- Stage changes to the working tree
$ git add .
- Stash the contents of the staging area and thhe working tree
$ git stash
- Then checkout the correct branch
$ git checkout master
- Remove a single stashed state from the stash list and apply it on top of the current working tree state
$ git stash pop
- Verify that the state has been moved and the stash list is empty
$ git stash list
- Proceed as usual – edit, stage, commit to the correct branch.
— Oliver Frolovs, 2020