🌿 BranchingCommonly used
How to switch branches in Git
Move between branches in your repository.
Switch to a branch
git switch branch-nameSwitches to the specified branch. Modern syntax (Git 2.23+).
When to use: Recommended for Git 2.23+.
Switch to a branch (older syntax)
git checkout branch-nameClassic way to switch branches. Works in all Git versions.
Switch to previous branch
git switch -Switches back to the branch you were on before. The - means "previous".
When to use: Quick way to toggle between two branches.
Switch and discard local changes
git checkout --force branch-nameSwitches branch and discards any local uncommitted changes.
Discards all uncommitted changes permanently. Stash first if you want to keep them.