Gatlin.io Icon
Image of Austin Gatlin's face
March 15, 2022

Git Switch

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.