{
    "content": [
        {
            "type": "text",
            "text": "# git-switch (man)\n\n## NAME\n\ngit-switch - Switch branches\n\n## SYNOPSIS\n\ngit switch [<options>] [--no-guess] <branch>\ngit switch [<options>] --detach [<start-point>]\ngit switch [<options>] (-c|-C) <new-branch> [<start-point>]\ngit switch [<options>] --orphan <new-branch>\n\n## DESCRIPTION\n\nSwitch to a specified branch. The working tree and the index are updated to match the branch.\nAll new commits will be added to the tip of this branch.\n\n## TLDR\n\n> Switch between Git branches. Requires Git version 2.23+.\n\n- Switch to an existing branch:\n  `git switch {{branch_name}}`\n- Create a new branch and switch to it:\n  `git switch {{-c|--create}} {{branch_name}}`\n- Create a new branch based on an existing commit and switch to it:\n  `git switch {{-c|--create}} {{branch_name}} {{commit}}`\n- Switch to the previous branch:\n  `git switch -`\n- Switch to a branch and update all submodules to match:\n  `git switch --recurse-submodules {{branch_name}}`\n- Switch to a branch and automatically merge the current branch and any uncommitted changes into it:\n  `git switch {{-m|--merge}} {{branch_name}}`\n- Switch to a tag or commit:\n  `git switch {{-d|--detach}} {{tag|commit}}`\n- Switch to another remote's branch:\n  `git switch {{-t|--track}} {{remote_name}}/{{branch}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (14 subsections)\n- **EXAMPLES**\n- **SEE ALSO**\n- **GIT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "git-switch",
        "section": "",
        "mode": "man",
        "summary": "git-switch - Switch branches",
        "synopsis": "git switch [<options>] [--no-guess] <branch>\ngit switch [<options>] --detach [<start-point>]\ngit switch [<options>] (-c|-C) <new-branch> [<start-point>]\ngit switch [<options>] --orphan <new-branch>",
        "tldr_summary": "Switch between Git branches. Requires Git version 2.23+.",
        "tldr_examples": [
            {
                "description": "Switch to an existing branch",
                "command": "git switch {{branch_name}}"
            },
            {
                "description": "Create a new branch and switch to it",
                "command": "git switch {{-c|--create}} {{branch_name}}"
            },
            {
                "description": "Create a new branch based on an existing commit and switch to it",
                "command": "git switch {{-c|--create}} {{branch_name}} {{commit}}"
            },
            {
                "description": "Switch to the previous branch",
                "command": "git switch -"
            },
            {
                "description": "Switch to a branch and update all submodules to match",
                "command": "git switch --recurse-submodules {{branch_name}}"
            },
            {
                "description": "Switch to a branch and automatically merge the current branch and any uncommitted changes into it",
                "command": "git switch {{-m|--merge}} {{branch_name}}"
            },
            {
                "description": "Switch to a tag or commit",
                "command": "git switch {{-d|--detach}} {{tag|commit}}"
            },
            {
                "description": "Switch to another remote's branch",
                "command": "git switch {{-t|--track}} {{remote_name}}/{{branch}}"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-c",
                "long": "--create",
                "arg": "<new-branch>",
                "description": "Create a new branch named <new-branch> starting at <start-point> before switching to the branch. This is a convenient shortcut for: $ git branch <new-branch> $ git switch <new-branch>"
            },
            {
                "flag": "-C",
                "long": "--force-create",
                "arg": "<new-branch>",
                "description": "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>"
            },
            {
                "flag": "-d",
                "long": "--detach",
                "arg": null,
                "description": "Switch to a commit for inspection and discardable experiments. See the \"DETACHED HEAD\" section in git-checkout(1) for details."
            },
            {
                "flag": "",
                "long": "--no-guess",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "An alias for --discard-changes."
            },
            {
                "flag": "",
                "long": "--discard-changes",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "-m",
                "long": "--merge",
                "arg": null,
                "description": "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). --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) and \"diff3\" (in addition to what is shown by \"merge\" style, shows the original contents)."
            },
            {
                "flag": "-q",
                "long": "--quiet",
                "arg": null,
                "description": "Quiet, suppress feedback messages."
            },
            {
                "flag": "",
                "long": "--no-progress",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "-t",
                "long": "--track",
                "arg": null,
                "description": "When creating a new branch, set up \"upstream\" configuration. -c is implied. See --track in git-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."
            },
            {
                "flag": "",
                "long": "--no-track",
                "arg": null,
                "description": "Do not set up \"upstream\" configuration, even if the branch.autoSetupMerge configuration variable is true."
            },
            {
                "flag": "",
                "long": "--orphan",
                "arg": "<new-branch>",
                "description": "Create a new orphan branch, named <new-branch>. All tracked files are removed."
            },
            {
                "flag": "",
                "long": "--ignore-other-worktrees",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "",
                "long": "--no-recurse-submodules",
                "arg": null,
                "description": "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), this will detach HEAD of 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 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"
        ],
        "see_also": [
            {
                "name": "git-checkout",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-checkout/1/json"
            },
            {
                "name": "git-branch",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-branch/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 20,
                "subsections": [
                    {
                        "name": "-c <new-branch>, --create <new-branch>",
                        "lines": 7,
                        "flag": "-c",
                        "long": "--create",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "-C <new-branch>, --force-create <new-branch>",
                        "lines": 7,
                        "flag": "-C",
                        "long": "--force-create",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "-d, --detach",
                        "lines": 3,
                        "flag": "-d",
                        "long": "--detach"
                    },
                    {
                        "name": "--guess, --no-guess",
                        "lines": 16,
                        "long": "--no-guess"
                    },
                    {
                        "name": "-f, --force",
                        "lines": 2,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "--discard-changes",
                        "lines": 5,
                        "long": "--discard-changes"
                    },
                    {
                        "name": "-m, --merge",
                        "lines": 16,
                        "flag": "-m",
                        "long": "--merge"
                    },
                    {
                        "name": "-q, --quiet",
                        "lines": 2,
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "--progress, --no-progress",
                        "lines": 4,
                        "long": "--no-progress"
                    },
                    {
                        "name": "-t, --track",
                        "lines": 11,
                        "flag": "-t",
                        "long": "--track"
                    },
                    {
                        "name": "--no-track",
                        "lines": 3,
                        "long": "--no-track"
                    },
                    {
                        "name": "--orphan <new-branch>",
                        "lines": 2,
                        "long": "--orphan",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "--ignore-other-worktrees",
                        "lines": 4,
                        "long": "--ignore-other-worktrees"
                    },
                    {
                        "name": "--recurse-submodules, --no-recurse-submodules",
                        "lines": 5,
                        "long": "--no-recurse-submodules"
                    }
                ]
            },
            {
                "name": "EXAMPLES",
                "lines": 58,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "git-switch - Switch branches\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git switch [<options>] [--no-guess] <branch>\ngit switch [<options>] --detach [<start-point>]\ngit switch [<options>] (-c|-C) <new-branch> [<start-point>]\ngit switch [<options>] --orphan <new-branch>\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Switch to a specified branch. The working tree and the index are updated to match the branch.\nAll new commits will be added to the tip of this branch.\n\nOptionally a new branch could be created with either -c, -C, automatically from a remote\nbranch of same name (see --guess), or detach the working tree from any branch with --detach,\nalong with switching.\n\nSwitching branches does not require a clean index and working tree (i.e. no differences\ncompared to HEAD). The operation is aborted however if the operation leads to loss of local\nchanges, unless told otherwise with --discard-changes or --merge.\n\nTHIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "<branch>\nBranch to switch to.\n\n<new-branch>\nName for the new branch.\n\n<start-point>\nThe starting point for the new branch. Specifying a <start-point> allows you to create a\nbranch based on some other point in history than where HEAD currently points. (Or, in the\ncase of --detach, allows you to inspect and detach from some other point.)\n\nYou can use the @{-N} syntax to refer to the N-th last branch/commit switched to using\n\"git switch\" or \"git checkout\" operation. You may also specify - which is synonymous to\n@{-1}. This is often used to switch quickly between two branches, or to undo a branch\nswitch by mistake.\n\nAs a special case, you may use A...B as a shortcut for the merge base of A and B if there\nis exactly one merge base. You can leave out at most one of A and B, in which case it\ndefaults to HEAD.\n",
                "subsections": [
                    {
                        "name": "-c <new-branch>, --create <new-branch>",
                        "content": "Create a new branch named <new-branch> starting at <start-point> before switching to the\nbranch. This is a convenient shortcut for:\n\n$ git branch <new-branch>\n$ git switch <new-branch>\n\n",
                        "flag": "-c",
                        "long": "--create",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "-C <new-branch>, --force-create <new-branch>",
                        "content": "Similar to --create except that if <new-branch> already exists, it will be reset to\n<start-point>. This is a convenient shortcut for:\n\n$ git branch -f <new-branch>\n$ git switch <new-branch>\n\n",
                        "flag": "-C",
                        "long": "--force-create",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "-d, --detach",
                        "content": "Switch to a commit for inspection and discardable experiments. See the \"DETACHED HEAD\"\nsection in git-checkout(1) for details.\n",
                        "flag": "-d",
                        "long": "--detach"
                    },
                    {
                        "name": "--guess, --no-guess",
                        "content": "If <branch> is not found but there does exist a tracking branch in exactly one remote\n(call it <remote>) with a matching name, treat as equivalent to\n\n$ git switch -c <branch> --track <remote>/<branch>\n\nIf the branch exists in multiple remotes and one of them is named by the\ncheckout.defaultRemote configuration variable, we’ll use that one for the purposes of\ndisambiguation, even if the <branch> isn’t unique across all remotes. Set it to e.g.\ncheckout.defaultRemote=origin to always checkout remote branches from there if <branch>\nis ambiguous but exists on the origin remote. See also checkout.defaultRemote in git-\nconfig(1).\n\n--guess is the default behavior. Use --no-guess to disable it.\n\nThe default behavior can be set via the checkout.guess configuration variable.\n",
                        "long": "--no-guess"
                    },
                    {
                        "name": "-f, --force",
                        "content": "An alias for --discard-changes.\n",
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "--discard-changes",
                        "content": "Proceed even if the index or the working tree differs from HEAD. Both the index and\nworking tree are restored to match the switching target. If --recurse-submodules is\nspecified, submodule content is also restored to match the switching target. This is used\nto throw away local changes.\n",
                        "long": "--discard-changes"
                    },
                    {
                        "name": "-m, --merge",
                        "content": "If you have local modifications to one or more files that are different between the\ncurrent branch and the branch to which you are switching, the command refuses to switch\nbranches in order to preserve your modifications in context. However, with this option, a\nthree-way merge between the current branch, your working tree contents, and the new\nbranch is done, and you will be on the new branch.\n\nWhen a merge conflict happens, the index entries for conflicting paths are left unmerged,\nand you need to resolve the conflicts and mark the resolved paths with git add (or git rm\nif the merge should result in deletion of the path).\n\n--conflict=<style>\nThe same as --merge option above, but changes the way the conflicting hunks are\npresented, overriding the merge.conflictStyle configuration variable. Possible values are\n\"merge\" (default) and \"diff3\" (in addition to what is shown by \"merge\" style, shows the\noriginal contents).\n",
                        "flag": "-m",
                        "long": "--merge"
                    },
                    {
                        "name": "-q, --quiet",
                        "content": "Quiet, suppress feedback messages.\n",
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "--progress, --no-progress",
                        "content": "Progress status is reported on the standard error stream by default when it is attached\nto a terminal, unless --quiet is specified. This flag enables progress reporting even if\nnot attached to a terminal, regardless of --quiet.\n",
                        "long": "--no-progress"
                    },
                    {
                        "name": "-t, --track",
                        "content": "When creating a new branch, set up \"upstream\" configuration.  -c is implied. See --track\nin git-branch(1) for details.\n\nIf no -c option is given, the name of the new branch will be derived from the\nremote-tracking branch, by looking at the local part of the refspec configured for the\ncorresponding remote, and then stripping the initial part up to the \"*\". This would tell\nus to use hack as the local branch when branching off of origin/hack (or\nremotes/origin/hack, or even refs/remotes/origin/hack). If the given name has no slash,\nor the above guessing results in an empty name, the guessing is aborted. You can\nexplicitly give a name with -c in such a case.\n",
                        "flag": "-t",
                        "long": "--track"
                    },
                    {
                        "name": "--no-track",
                        "content": "Do not set up \"upstream\" configuration, even if the branch.autoSetupMerge configuration\nvariable is true.\n",
                        "long": "--no-track"
                    },
                    {
                        "name": "--orphan <new-branch>",
                        "content": "Create a new orphan branch, named <new-branch>. All tracked files are removed.\n",
                        "long": "--orphan",
                        "arg": "<new-branch>"
                    },
                    {
                        "name": "--ignore-other-worktrees",
                        "content": "git switch refuses when the wanted ref is already checked out by another worktree. This\noption makes it check the ref out anyway. In other words, the ref can be held by more\nthan one worktree.\n",
                        "long": "--ignore-other-worktrees"
                    },
                    {
                        "name": "--recurse-submodules, --no-recurse-submodules",
                        "content": "Using --recurse-submodules will update the content of all active submodules according to\nthe commit recorded in the superproject. If nothing (or --no-recurse-submodules) is used,\nsubmodules working trees will not be updated. Just like git-submodule(1), this will\ndetach HEAD of the submodules.\n",
                        "long": "--no-recurse-submodules"
                    }
                ]
            },
            "EXAMPLES": {
                "content": "The following command switches to the \"master\" branch:\n\n$ git switch master\n\n\nAfter working in the wrong branch, switching to the correct branch would be done using:\n\n$ git switch mytopic\n\n\nHowever, your \"wrong\" branch and correct \"mytopic\" branch may differ in files that you have\nmodified locally, in which case the above switch would fail like this:\n\n$ git switch mytopic\nerror: You have local changes to 'frotz'; not switching branches.\n\n\nYou can give the -m flag to the command, which would try a three-way merge:\n\n$ git switch -m mytopic\nAuto-merging frotz\n\n\nAfter this three-way merge, the local modifications are not registered in your index file, so\ngit diff would show you what changes you made since the tip of the new branch.\n\nTo switch back to the previous branch before we switched to mytopic (i.e. \"master\" branch):\n\n$ git switch -\n\n\nYou can grow a new branch from any commit. For example, switch to \"HEAD~3\" and create branch\n\"fixup\":\n\n$ git switch -c fixup HEAD~3\nSwitched to a new branch 'fixup'\n\n\nIf you want to start a new branch from a remote branch of the same name:\n\n$ git switch new-topic\nBranch 'new-topic' set up to track remote branch 'new-topic' from 'origin'\nSwitched to a new branch 'new-topic'\n\n\nTo check out commit HEAD~3 for temporary inspection or experiment without creating a new\nbranch:\n\n$ git switch --detach HEAD~3\nHEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits'\n\n\nIf it turns out whatever you have done is worth keeping, you can always create a new name for\nit (without switching away):\n\n$ git switch -c good-surprises\n\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "git-checkout(1), git-branch(1)\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                                GIT-SWITCH(1)",
                "subsections": []
            }
        }
    }
}