Switch Branches
Switch moves you between branches. The files change to match the branch you land on.
Switch to main
The recipe on main has no vanilla. Vanilla lives only on the other branch.
$ git switch main
$ cat recipe.txtSwitch back
The vanilla returns with the branch.
$ git switch add-recipe
$ cat recipe.txtExample
$ git switch main
$ cat recipe.txtKey points
- Switch with a branch name moves you there.
- Your work follows you only when it is saved.
- Unfinished changes stay in the files when you switch.
- Git stops you from switching when the change would be lost.
- The status command always says which branch you are on.
- Read a file after switching to see the difference.
Here, switching changes the files. The recipe on main has no vanilla, because vanilla was saved on the other branch.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What changes when you switch branches?