[![Git](https://git-scm.com/images/logo@2x.png)](https://git-scm.com/) --distributed-even-if-your-workflow-isnt
![](https://git-scm.com/images/dark-mode.svg)
  * [About](https://git-scm.com/about)
    * [Trademark](https://git-scm.com/about/trademark)
  * [Learn](https://git-scm.com/learn)
    * [Book](https://git-scm.com/book)
    * [Cheat Sheet](https://git-scm.com/cheat-sheet)
    * [Videos](https://git-scm.com/videos)
    * [External Links](https://git-scm.com/doc/ext)
  * [Tools](https://git-scm.com/tools)
    * [Command Line](https://git-scm.com/tools/command-line)
    * [GUIs](https://git-scm.com/tools/guis)
    * [Hosting](https://git-scm.com/tools/hosting)
  * [Reference](https://git-scm.com/docs)
  * [Install](https://git-scm.com/install/linux)
  * [Community](https://git-scm.com/community)


  * Table of Contents
    * [NAME](https://git-scm.com/docs/git-switch#_name)
    * [SYNOPSIS](https://git-scm.com/docs/git-switch#_synopsis)
    * [DESCRIPTION](https://git-scm.com/docs/git-switch#_description)
    * [OPTIONS](https://git-scm.com/docs/git-switch#_options)
    * [EXAMPLES](https://git-scm.com/docs/git-switch#_examples)
    * [CONFIGURATION](https://git-scm.com/docs/git-switch#_configuration)
    * [SEE ALSO](https://git-scm.com/docs/git-switch#_see_also)
    * [GIT](https://git-scm.com/docs/git-switch#_git)


[ English ▾](https://git-scm.com/docs/git-switch)
Localized versions of **git-switch** manual
  1. [English ](https://git-scm.com/docs/git-switch)
  2. [Français ](https://git-scm.com/docs/git-switch/fr)
  3. [Português (Brasil) ](https://git-scm.com/docs/git-switch/pt_BR)
  4. [українська мова ](https://git-scm.com/docs/git-switch/uk)
  5. [简体中文 ](https://git-scm.com/docs/git-switch/zh_HANS-CN)

Want to read in your language or fix typos?
[You can help translate this page](https://github.com/jnavila/git-manpages-l10n).
[Topics ▾](https://git-scm.com/docs/git-switch)
### Setup and Config
  * [ git ](https://git-scm.com/docs/git)
  * [ config ](https://git-scm.com/docs/git-config)
  * [ help ](https://git-scm.com/docs/git-help)
  * [ bugreport ](https://git-scm.com/docs/git-bugreport)
  * [ Credential helpers ](https://git-scm.com/doc/credential-helpers)


### Getting and Creating Projects
  * [ init ](https://git-scm.com/docs/git-init)
  * [ clone ](https://git-scm.com/docs/git-clone)


### Basic Snapshotting
  * [ add ](https://git-scm.com/docs/git-add)
  * [ status ](https://git-scm.com/docs/git-status)
  * [ diff ](https://git-scm.com/docs/git-diff)
  * [ commit ](https://git-scm.com/docs/git-commit)
  * [ notes ](https://git-scm.com/docs/git-notes)
  * [ restore ](https://git-scm.com/docs/git-restore)
  * [ reset ](https://git-scm.com/docs/git-reset)
  * [ rm ](https://git-scm.com/docs/git-rm)
  * [ mv ](https://git-scm.com/docs/git-mv)


### Branching and Merging
  * [ branch ](https://git-scm.com/docs/git-branch)
  * [ checkout ](https://git-scm.com/docs/git-checkout)
  * [ switch ](https://git-scm.com/docs/git-switch)
  * [ merge ](https://git-scm.com/docs/git-merge)
  * [ mergetool ](https://git-scm.com/docs/git-mergetool)
  * [ log ](https://git-scm.com/docs/git-log)
  * [ stash ](https://git-scm.com/docs/git-stash)
  * [ tag ](https://git-scm.com/docs/git-tag)
  * [ worktree ](https://git-scm.com/docs/git-worktree)


### Sharing and Updating Projects
  * [ fetch ](https://git-scm.com/docs/git-fetch)
  * [ pull ](https://git-scm.com/docs/git-pull)
  * [ push ](https://git-scm.com/docs/git-push)
  * [ remote ](https://git-scm.com/docs/git-remote)
  * [ submodule ](https://git-scm.com/docs/git-submodule)


### Inspection and Comparison
  * [ show ](https://git-scm.com/docs/git-show)
  * [ log ](https://git-scm.com/docs/git-log)
  * [ diff ](https://git-scm.com/docs/git-diff)
  * [ difftool ](https://git-scm.com/docs/git-difftool)
  * [ range-diff ](https://git-scm.com/docs/git-range-diff)
  * [ shortlog ](https://git-scm.com/docs/git-shortlog)
  * [ describe ](https://git-scm.com/docs/git-describe)


### Patching
  * [ apply ](https://git-scm.com/docs/git-apply)
  * [ cherry-pick ](https://git-scm.com/docs/git-cherry-pick)
  * [ diff ](https://git-scm.com/docs/git-diff)
  * [ rebase ](https://git-scm.com/docs/git-rebase)
  * [ revert ](https://git-scm.com/docs/git-revert)


### Debugging
  * [ bisect ](https://git-scm.com/docs/git-bisect)
  * [ blame ](https://git-scm.com/docs/git-blame)
  * [ grep ](https://git-scm.com/docs/git-grep)


### Email
  * [ am ](https://git-scm.com/docs/git-am)
  * [ apply ](https://git-scm.com/docs/git-apply)
  * [ imap-send ](https://git-scm.com/docs/git-imap-send)
  * [ format-patch ](https://git-scm.com/docs/git-format-patch)
  * [ send-email ](https://git-scm.com/docs/git-send-email)
  * [ request-pull ](https://git-scm.com/docs/git-request-pull)


### External Systems
  * [ svn ](https://git-scm.com/docs/git-svn)
  * [ fast-import ](https://git-scm.com/docs/git-fast-import)


### Server Admin
  * [ daemon ](https://git-scm.com/docs/git-daemon)
  * [ update-server-info ](https://git-scm.com/docs/git-update-server-info)


### Guides
  * [ gitattributes ](https://git-scm.com/docs/gitattributes)
  * [ Command-line interface conventions ](https://git-scm.com/docs/gitcli)
  * [ Everyday Git ](https://git-scm.com/docs/giteveryday)
  * [ Frequently Asked Questions (FAQ) ](https://git-scm.com/docs/gitfaq)
  * [ Glossary ](https://git-scm.com/docs/gitglossary)
  * [ Hooks ](https://git-scm.com/docs/githooks)
  * [ gitignore ](https://git-scm.com/docs/gitignore)
  * [ gitmodules ](https://git-scm.com/docs/gitmodules)
  * [ Revisions ](https://git-scm.com/docs/gitrevisions)
  * [ Submodules ](https://git-scm.com/docs/gitsubmodules)
  * [ Tutorial ](https://git-scm.com/docs/gittutorial)
  * [ Workflows ](https://git-scm.com/docs/gitworkflows)
  * [ All guides... ](https://git-scm.com/docs/git#_guides)


### Administration
  * [ clean ](https://git-scm.com/docs/git-clean)
  * [ gc ](https://git-scm.com/docs/git-gc)
  * [ fsck ](https://git-scm.com/docs/git-fsck)
  * [ reflog ](https://git-scm.com/docs/git-reflog)
  * [ filter-branch ](https://git-scm.com/docs/git-filter-branch)
  * [ instaweb ](https://git-scm.com/docs/git-instaweb)
  * [ archive ](https://git-scm.com/docs/git-archive)
  * [ bundle ](https://git-scm.com/docs/git-bundle)


### Plumbing Commands
  * [ cat-file ](https://git-scm.com/docs/git-cat-file)
  * [ check-ignore ](https://git-scm.com/docs/git-check-ignore)
  * [ checkout-index ](https://git-scm.com/docs/git-checkout-index)
  * [ commit-tree ](https://git-scm.com/docs/git-commit-tree)
  * [ count-objects ](https://git-scm.com/docs/git-count-objects)
  * [ diff-index ](https://git-scm.com/docs/git-diff-index)
  * [ for-each-ref ](https://git-scm.com/docs/git-for-each-ref)
  * [ hash-object ](https://git-scm.com/docs/git-hash-object)
  * [ ls-files ](https://git-scm.com/docs/git-ls-files)
  * [ ls-tree ](https://git-scm.com/docs/git-ls-tree)
  * [ merge-base ](https://git-scm.com/docs/git-merge-base)
  * [ read-tree ](https://git-scm.com/docs/git-read-tree)
  * [ rev-list ](https://git-scm.com/docs/git-rev-list)
  * [ rev-parse ](https://git-scm.com/docs/git-rev-parse)
  * [ show-ref ](https://git-scm.com/docs/git-show-ref)
  * [ symbolic-ref ](https://git-scm.com/docs/git-symbolic-ref)
  * [ update-index ](https://git-scm.com/docs/git-update-index)
  * [ update-ref ](https://git-scm.com/docs/git-update-ref)
  * [ verify-pack ](https://git-scm.com/docs/git-verify-pack)
  * [ write-tree ](https://git-scm.com/docs/git-write-tree)


[ Latest version ▾ ](https://git-scm.com/docs/git-switch) git-switch last updated in 2.51.0
Changes in the **git-switch** manual
  1. 2.51.1 → 2.53.0 no changes
  2. 2.51.0 no changes
  3. 2.50.1 no changes
  4. [2.50.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2025-06-16_ ](https://git-scm.com/docs/git-switch/2.50.0)
  5. 2.44.1 → 2.49.1 no changes
  6. [2.44.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2024-02-23_ ](https://git-scm.com/docs/git-switch/2.44.0)
  7. 2.43.2 → 2.43.7 no changes
  8. [2.43.1 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2024-02-09_ ](https://git-scm.com/docs/git-switch/2.43.1)
  9. [2.43.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2023-11-20_ ](https://git-scm.com/docs/git-switch/2.43.0)
  10. 2.38.1 → 2.42.4 no changes
  11. [2.38.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2022-10-02_ ](https://git-scm.com/docs/git-switch/2.38.0)
  12. 2.35.1 → 2.37.7 no changes
  13. [2.35.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2022-01-24_ ](https://git-scm.com/docs/git-switch/2.35.0)
  14. 2.30.1 → 2.34.8 no changes
  15. [2.30.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2020-12-27_ ](https://git-scm.com/docs/git-switch/2.30.0)
  16. 2.27.1 → 2.29.3 no changes
  17. [2.27.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2020-06-01_ ](https://git-scm.com/docs/git-switch/2.27.0)
  18. 2.23.1 → 2.26.3 no changes
  19. [2.23.0 ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/green-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/red-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) ![](https://git-scm.com/images/icons/grey-dot.png) _2019-08-16_ ](https://git-scm.com/docs/git-switch/2.23.0)


Check your version of git by running
`git --version`
##  [](https://git-scm.com/docs/git-switch#_name)NAME
git-switch - Switch branches
##  [](https://git-scm.com/docs/git-switch#_synopsis)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>_
```

##  [](https://git-scm.com/docs/git-switch#_description)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`.
##  [](https://git-scm.com/docs/git-switch#_options)OPTIONS

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-branch)_< branch>_

Branch to switch to.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-new-branch)_< new-branch>_

Name for the new branch.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-start-point)_< 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 where `HEAD` currently 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`.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--cnew-branch)`-c` _< new-branch>_


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---createnew-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).

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--Cnew-branch)`-C` _< new-branch>_


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---force-createnew-branch)`--force-create` _< new-branch>_

Similar to `--create` except 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>_
```


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--d)`-d`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---detach)`--detach`

Switch to a commit for inspection and discardable experiments. See the "DETACHED HEAD" section in [git-checkout[1]](https://git-scm.com/docs/git-checkout) for details.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---guess)`--guess`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---no-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]](https://git-scm.com/docs/git-config).
`--guess` is the default behavior. Use `--no-guess` to disable it.
The default behavior can be set via the `checkout.guess` configuration variable.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--f)`-f`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---force)`--force`

An alias for `--discard-changes`.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---discard-changes)`--discard-changes`

Proceed even if the index or the working tree differs from `HEAD`. Both the index and working tree are restored to match the switching target. If `--recurse-submodules` is specified, submodule content is also restored to match the switching target. This is used to throw away local changes.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--m)`-m`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---merge)`--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 refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.
When a merge conflict happens, the index entries for conflicting paths are left unmerged, and you need to resolve the conflicts and mark the resolved paths with `git` `add` (or `git` `rm` if the merge should result in deletion of the path).

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---conflictstyle)`--conflict=`_< style>_

The same as `--merge` option above, but changes the way the conflicting hunks are presented, overriding the `merge.conflictStyle` configuration variable. Possible values are `merge` (default), `diff3`, and `zdiff3`.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--q)`-q`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---quiet)`--quiet`

Quiet, suppress feedback messages.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---progress)`--progress`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---no-progress)`--no-progress`

Progress status is reported on the standard error stream by default when it is attached to a terminal, unless `--quiet` is specified. This flag enables progress reporting even if not attached to a terminal, regardless of `--quiet`.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt--t)`-t`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---trackdirectinherit)`--track`[ (`direct`|`inherit`)]

When creating a new branch, set up "upstream" configuration. `-c` is implied. See `--track` in [git-branch[1]](https://git-scm.com/docs/git-branch) 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.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---no-track)`--no-track`

Do not set up "upstream" configuration, even if the `branch.autoSetupMerge` configuration variable is true.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---orphannew-branch)`--orphan` _< new-branch>_

Create a new unborn branch, named _< new-branch>_. All tracked files are removed.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---ignore-other-worktrees)`--ignore-other-worktrees`

`git` `switch` refuses 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.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---recurse-submodules)`--recurse-submodules`


[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---no-recurse-submodules)`--no-recurse-submodules`

Using `--recurse-submodules` will 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 like [git-submodule[1]](https://git-scm.com/docs/git-submodule), this will detach `HEAD` of the submodules.
##  [](https://git-scm.com/docs/git-switch#_examples)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 would try a three-way merge:
```
$ git switch -m mytopic
Auto-merging frotz
```

After this three-way merge, the local modifications 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
```

##  [](https://git-scm.com/docs/git-switch#_configuration)CONFIGURATION
Everything below this line in this section is selectively included from the [git-config[1]](https://git-scm.com/docs/git-config) documentation. The content is the same as what’s found there:

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-checkoutdefaultRemote)`checkout.defaultRemote`

When you run `git` `checkout` _< something>_ or `git` `switch` _< something>_ and only have one remote, it may implicitly fall back on checking out and tracking e.g. `origin/`_< something>_. This stops working as soon as you have more than one remote with a _< something>_ reference. This setting allows for setting the name of a preferred remote that should always win when it comes to disambiguation. The typical use-case is to set this to `origin`.
Currently this is used by [git-switch[1]](https://git-scm.com/docs/git-switch) and [git-checkout[1]](https://git-scm.com/docs/git-checkout) when `git` `checkout` _< something>_ or `git` `switch` _< something>_ will checkout the _< something>_ branch on another remote, and by [git-worktree[1]](https://git-scm.com/docs/git-worktree) when `git` `worktree` `add` refers to a remote branch. This setting might be used for other checkout-like commands or functionality in the future.

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-checkoutguess)`checkout.guess`

Provides the default value for the `--guess` or `--no-guess` option in `git` `checkout` and `git` `switch`. See [git-switch[1]](https://git-scm.com/docs/git-switch) and [git-checkout[1]](https://git-scm.com/docs/git-checkout).

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-checkoutworkers)`checkout.workers`

The number of parallel workers to use when updating the working tree. The default is one, i.e. sequential execution. 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.
---|---

[](https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-checkoutthresholdForParallelism)`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.
##  [](https://git-scm.com/docs/git-switch#_see_also)SEE ALSO
[git-checkout[1]](https://git-scm.com/docs/git-checkout), [git-branch[1]](https://git-scm.com/docs/git-branch)
##  [](https://git-scm.com/docs/git-switch#_git)GIT
Part of the [git[1]](https://git-scm.com/docs/git) suite
### switch
[About this site](https://git-scm.com/site)
Patches, suggestions, and comments are welcome.
Git is a member of [Software Freedom Conservancy](https://git-scm.com/sfc)
