switch is the modern verb; checkout is overloaded
For years, git checkout did two completely unrelated jobs: switching branches and restoring files from history. That overloading is the source of countless beginner mistakes — typing git checkout file.js meaning "open this file" and accidentally discarding all uncommitted edits. Git 2.23 (2019) split these responsibilities into git switch (branches) and git restore (files). The new commands are clearer, safer, and what every modern guide should use.
git switch <branch> changes the current branch. git switch -c <branch> creates and switches in one step. git switch - jumps to the previous branch (like cd -). git switch --detach <commit> intentionally enters detached HEAD. The old git checkout still works and you will see it in old guides, but in new code, prefer switch.
Detached HEAD is the state where HEAD points directly at a commit instead of at a branch name. It is not an error; it is a valid state, used for inspecting old commits or building from a tagged release. The risk: any commits you make in this state are not on any branch. If you switch away, those commits become orphaned. The escape hatch: git switch -c rescue-branch at the detached commit creates a branch pointing right where HEAD is, anchoring the work.
Before you switch, Git checks the working tree. If switching would overwrite uncommitted changes, Git refuses. Two clean responses: commit (or amend) what you have, or stash it (git stash push -u). Some teams configure git config --global advice.detachedHead false to silence the verbose detached-HEAD message once they understand it.