Git Cheatsheet - Quick Git Command Reference

Quick reference for common Git commands. Search, copy, and use Git commands instantly.

Share
Back to Git Cheatsheet

git checkout

Switch branches or restore working tree files

Syntax

git checkout [options] <branch> | <commit> | -- <file>

Common Options

OptionDescription
-b <branch>Create and switch to new branch
-t, --trackTrack remote branch
--track origin/<branch>Track specific remote branch
--detachSwitch to detached HEAD
-- <file>Restore file to last commit
-p, --patchInteractively select hunks to restore
-B <branch>Create/reset and switch branch

Examples

git checkout main

Switch to main branch

git checkout -b feature/new

Create and switch to new branch

git checkout -- file.txt

Discard working tree changes

git checkout --track origin/dev

Track remote branch and switch

Related Tools

More Code & Dev Tools