Git 2 reference · Branching and Merging
git switch Command (Git)
Switch to another branch, or create one and switch to it with -c; the modern replacement for git checkout branches.
Git 2
Syntax
git switch BRANCH git switch -c NEW [START]
Parameters
| Parameter | Description |
|---|---|
-c NEW |
Create and switch. |
- |
Back to the previous branch. |
--detach COMMIT |
Look at an old commit without a branch. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c feature/cart
git branch --show-current
git switch -q -
git branch --show-current
Output
feature/cart main
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo draft > draft.txt
git switch -q -c experiment
git status -s
Output
?? draft.txt
Run this on your computer — see “Get Started” for setup.
Related
git branch· List, create, rename and delete branches, and see which branches are merged.git restore· Discard working-tree changes to files, or unstage files, without touching other work.- Branches · tutorial