git/checkout

Switch Branches

Switch branches or restore files

git
checkout
branch

Command

git checkout

Explanation

git checkout is used to switch branches or restore files. It switches branches or restores files.

Examples

Switch to main branch

git checkout main

Create and switch to new branch

git checkout -b new-branch

Discard changes to file

git checkout file.txt