Git switch is a recently introduced command as of git v2.23. Git switch lets you switch branches with a dirty working directory (git status
red text) and a dirty index (git status
yellow text). It will move those uncommitted changes to the new branch from the old branch. I.e., the old branch is no longer dirty.
If the branch doesn't already exist, you can create it with the -c
flag.
git switch [branch-name] # when branch already exits
git switch -c [branch-name] # when creating a new branch
I have a note about the Git Working Directory and Index if you want to explore those concepts further.