git checkout Switch branches or restore files (older all-in-one)

The original multi-purpose command: it switches branches, creates them, and restores files. Newer Git splits those jobs into git switch and git restore, but checkout is everywhere in guides and scripts.

Synopsis

git checkout [OPTION]... BRANCH
git checkout [COMMIT] -- PATH...

Common options

Option or formWhat it does
BRANCHSwitch to that branch
-b NAMECreate a new branch and switch to it
-- PATHRestore a file from the index or a commit. This discards your edits
COMMITCheck out a commit, which leaves you in "detached HEAD"
-Go back to the previous branch

Examples

Switch branch
git checkout main
Create and switch
git checkout -b feature/search
Discard changes to a file
git checkout -- app.js
Restore a file from another branch
git checkout main -- config.json
Look at an old version
git checkout 3f2a9c1

Notes

See also

Last reviewed 2026-10-09.