Moving In-Progress Work Without Losing It
Git work often starts on the wrong branch. The fix is straightforward: move unstaged changes from the current branch to a freshly created one. The long way involves stashing everything, returning to the main branch, pulling the latest updates, cutting a new branch, and then unstashing the stashed files.
Here’s what that manual process looks like with the Git CLI:
git status
git stash --include-untracked
git checkout master
git pull
git branch content/sharis
git checkout content/sharis
git stash pop
GUI Shortcuts and a Simpler Command
Graphical Git clients like Git Tower can also follow the same step-by-step flow. The shortcut in Tower is to create the new branch directly from the current one, then double-click to switch over to it, taking your changes along. Other GUI tools may offer similar one-click moves.
There is also a much newer and cleaner command-line approach. Instead of staging, stashing, and switching manually, you can cut a new branch and carry over your changes in a single step:
TIL about `git switch`, which allows you to move your unstaged changes to a new branch.
— Wes Bos (@wesbos) January 6, 2022
Seems fairly new. I used to `git stash`, new branch, and then `git stash apply` pic.twitter.com/6Rd0fCJOcV
That command is:
git switch -c new-branch
Full documentation is available in the Git switch reference.



