GIT-SWITCH(1)
π NAME β git-switch(1) π
okay so welcome to the git-switch(1) manual page, bestie β we're switching branches and it's gonna be iconic β¨
git-switch β Switch branches π
π¦ SYNOPSIS π¦
git switch [<options>] [--no-guess] <branch>
git switch [<options>] --detach [<start-point>]
git switch [<options>] (-c|-C) <new-branch> [<start-point>]
git switch [<options>] --orphan <new-branch>
πΈ DESCRIPTION πΈ
Switch to a specified branch. The working tree and the index are updated to match the branch. All new commits will be added to the tip of this branch π«Ά
Optionally a new branch could be created with either -c, -C, automatically from a remote branch of same name (see --guess), or detach the working tree from any branch with --detach, along with switching.
Switching branches does not require a clean index and working tree (i.e. no differences compared to HEAD). The operation is aborted however if the operation leads to loss of local changes, unless told otherwise with --discard-changes or --merge π
π OPTIONS π
<branch>β Branch to switch to.<new-branch>β Name for the new branch.<start-point>β The starting point for the new branch. Specifying a<start-point>allows you to create a branch based on some other point in history than whereHEADcurrently points. (Or, in the case of--detach, allows you to inspect and detach from some other point.)
You can use the @{-<N>} syntax to refer to the <N>-th last branch/commit switched to using git switch or git checkout operation. You may also specify - which is synonymous to @{-1}. This is often used to switch quickly between two branches, or to undo a branch switch by mistake.
As a special case, you may use <rev-a>...<rev-b> as a shortcut for the merge base of <rev-a> and <rev-b> if there is exactly one merge base. You can leave out at most one of <rev-a> and <rev-b>, in which case it defaults to HEAD.
-c <new-branch>,--create <new-branch>β Create a new branch named<new-branch>starting at<start-point>before switching to the branch. This is the transactional equivalent of
$ git branch <new-branch>
$ git switch <new-branch>
that is to say, the branch is not reset/created unless git switch is successful (e.g., when the branch is in use in another worktree, not just the current branch stays the same, but the branch is not reset to the start-point, either).
-C <new-branch>,--force-create <new-branch>β Similar to--createexcept that if<new-branch>already exists, it will be reset to<start-point>. This is a convenient shortcut for:
$ git branch -f _<new-branch>_
$ git switch _<new-branch>_
-d,--detachβ Switch to a commit for inspection and discardable experiments. See the "DETACHED HEAD" section ingit-checkout(1)for details.--guess,--no-guessβ If<branch>is not found but there does exist a tracking branch in exactly one remote (call it<remote>) with a matching name, treat as equivalent to
$ git switch -c <branch> --track <remote>/<branch>
If the branch exists in multiple remotes and one of them is named by the checkout.defaultRemote configuration variable, weβll use that one for the purposes of disambiguation, even if the <branch> isnβt unique across all remotes. Set it to e.g. checkout.defaultRemote=origin to always checkout remote branches from there if <branch> is ambiguous but exists on the origin remote. See also checkout.defaultRemote in git-config(1).
--guess is the default behavior. Use --no-guess to disable it.
The default behavior can be set via the checkout.guess configuration variable.
-f,--forceβ An alias for--discard-changes.--discard-changesβ Proceed even if the index or the working tree differs fromHEAD. Both the index and working tree are restored to match the switching target. If--recurse-submodulesis specified, submodule content is also restored to match the switching target. This is used to throw away local changes π«£-m,--mergeβ If you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command normally refuses to switch branches in order to preserve your modifications in context. However, with this option, the conflicting local changes are automatically stashed before the switch and reapplied afterwards. If the local changes do not overlap with the differences between branches, the switch proceeds without stashing. If reapplying the stash results in conflicts, the entry is saved to the stash list. Resolve the conflicts and rungit stash dropwhen done, or clear the working tree (e.g. withgit reset --hard) before runninggit stash poplater to re-apply your changes.--conflict=<style>β The same as--mergeoption above, but changes the way the conflicting hunks are presented, overriding themerge.conflictStyleconfiguration variable. Possible values aremerge(default),diff3, andzdiff3.-q,--quietβ Quiet, suppress feedback messages.--progress,--no-progressβ Progress status is reported on the standard error stream by default when it is attached to a terminal, unless--quietis specified. This flag enables progress reporting even if not attached to a terminal, regardless of--quiet.-t,--track[ (direct|inherit)]β When creating a new branch, set up "upstream" configuration.-cis implied. See--trackingit-branch(1)for details.
If no -c option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec configured for the corresponding remote, and then stripping the initial part up to the *. This would tell us to use hack as the local branch when branching off of origin/hack (or remotes/origin/hack, or even refs/remotes/origin/hack). If the given name has no slash, or the above guessing results in an empty name, the guessing is aborted. You can explicitly give a name with -c in such a case.
--no-trackβ Do not set up "upstream" configuration, even if thebranch.autoSetupMergeconfiguration variable is true.--orphan <new-branch>β Create a new unborn branch, named<new-branch>. All tracked files are removed.--ignore-other-worktreesβgit switchrefuses when the wanted ref is already checked out by another worktree. This option makes it check the ref out anyway. In other words, the ref can be held by more than one worktree.--recurse-submodules,--no-recurse-submodulesβ Using--recurse-submoduleswill update the content of all active submodules according to the commit recorded in the superproject. If nothing (or--no-recurse-submodules) is used, submodules working trees will not be updated. Just likegit-submodule(1), this will detachHEADof the submodules.
π EXAMPLES π
The following command switches to the "master" branch:
$ git switch master
After working in the wrong branch, switching to the correct branch would be done using:
$ git switch mytopic
However, your "wrong" branch and correct "mytopic" branch may differ in files that you have modified locally, in which case the above switch would fail like this:
$ git switch mytopic
error: You have local changes to 'frotz'; not switching branches.
You can give the -m flag to the command, which will carry your local changes to the new branch:
$ git switch -m mytopic
Applied autostash.
Switched to branch 'mytopic'
The following paths have local changes:
M frotz
After the switch, the local modifications are reapplied and are not registered in your index file, so git diff would show you what changes you made since the tip of the new branch.
To switch back to the previous branch before we switched to mytopic (i.e. "master" branch):
$ git switch -
You can grow a new branch from any commit. For example, switch to "HEAD~3" and create branch "fixup":
$ git switch -c fixup HEAD~3
Switched to a new branch 'fixup'
If you want to start a new branch from a remote branch of the same name:
$ git switch new-topic
Branch `new-topic` set up to track remote branch `new-topic` from `origin`
Switched to a new branch `new-topic`
To check out commit HEAD~3 for temporary inspection or experiment without creating a new branch:
$ git switch --detach HEAD~3
HEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits'
If it turns out whatever you have done is worth keeping, you can always create a new name for it (without switching away):
$ git switch -c good-surprises
β¨ CONFIGURATION β¨
Okay bestie, everything below this line in this section is selectively included from the git-config(1) docs β the content is the same as whatβs found there. Same facts, same energy. π
π checkout.defaultRemote
So picture this: you run git checkout <something> or git switch <something>, and youβve got exactly one remote. Git might just quietly fall back on checking out and tracking, like, origin/<something>. Iconic. But the second you have more than one remote with a <something> reference? That fallback stops working. This setting lets you name a preferred remote that always wins when it comes to disambiguation. The typical use-case is to set this to origin.
Right now this is used by git-switch(1) and git-checkout(1) when git checkout <something> or git switch <something> will checkout the <something> branch on another remote, and by git-worktree(1) when git worktree add refers to a remote branch. This setting might be used for other checkout-like commands or functionality in the future. π
πΈ checkout.guess
This one provides the default value for the --guess or --no-guess option in git checkout and git switch. Cute, right? See git-switch(1) and git-checkout(1). Thatβs the whole vibe. β¨
π checkout.workers
How many parallel workers should Git use when updating the working tree? This is that number. The default is one, i.e. sequential execution β one thing at a time, very chill. If set to a value less than one, Git will use as many workers as the number of logical cores available. This setting and checkout.thresholdForParallelism affect all commands that perform checkout. E.g. checkout, clone, reset, sparse-checkout, etc.
Note π«Ά Parallel checkout usually delivers better performance for repositories located on SSDs or over NFS. For repositories on spinning disks and/or machines with a small number of cores, the default sequential checkout often performs better. The size and compression level of a repository might also influence how well the parallel version performs.
β checkout.thresholdForParallelism
When running parallel checkout with a small number of files, the cost of subprocess spawning and inter-process communication might outweigh the parallelization gains. This setting allows you to define the minimum number of files for which parallel checkout should be attempted. The default is 100. Periodt. π
π SEE ALSO π
π GIT π
Part of the git(1) suite. Your fave family. π
Thatβs the whole page, bestie! This iconic little manual is Git 2.56.0, dated 2026-09-27 β go switch branches like a main character. π¦π
π¦ where this page comes from
- arch rolling: git 2.56.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms