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 switch

Switch branches (Git 2.23+, replaces checkout)

Syntax

git switch [options] [<branch>]

Common Options

OptionDescription
-c, --create <name>Create and switch to new branch
-C <name>Create/reset and switch branch
--detachSwitch to detached HEAD
-d, --detachDetach HEAD
-t, --trackSet upstream tracking
--no-trackDo not set tracking
--discard-changesDiscard changes and switch

Examples

git switch main

Switch to main branch

git switch -c feature/new

Create and switch to new branch

git switch -t origin/dev

Track remote branch and switch

Related Tools

More Code & Dev Tools