Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-switch.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-switch.adoc` 289 lines ยท 9124 bytes Raw Blame History 1 git-switch(1) 2 ============= 3 4 NAME 5 ---- 6 git-switch - Switch branches 7 8 SYNOPSIS 9 -------- 10 [synopsis] 11 git switch [] [--no-guess] 12 git switch [] --detach [] 13 git switch [] (-c|-C) [] 14 git switch [] --orphan 15 16 DESCRIPTION 17 ----------- 18 Switch to a specified branch. The working tree and the index are 19 updated to match the branch. All new commits will be added to the tip 20 of this branch. 21 22 Optionally a new branch could be created with either `-c`, `-C`, 23 automatically from a remote branch of same name (see `--guess`), or 24 detach the working tree from any branch with `--detach`, along with 25 switching. 26 27 Switching branches does not require a clean index and working tree 28 (i.e. no differences compared to `HEAD`). The operation is aborted 29 however if the operation leads to loss of local changes, unless told 30 otherwise with `--discard-changes` or `--merge`. 31 32 OPTIONS 33 ------- 34 __:: 35 Branch to switch to. 36 37 __:: 38 Name for the new branch. 39 40 __:: 41 The starting point for the new branch. Specifying a 42 __ allows you to create a branch based on some 43 other point in history than where `HEAD` currently points. (Or, 44 in the case of `--detach`, allows you to inspect and detach 45 from some other point.) 46 + 47 You can use the `@{-}` syntax to refer to the __-th last 48 branch/commit switched to using `git switch` or `git checkout` 49 operation. You may also specify `-` which is synonymous to `@{-1}`. 50 This is often used to switch quickly between two branches, or to undo 51 a branch switch by mistake. 52 + 53 As a special case, you may use `...` as a shortcut for the merge 54 base of __ and __ if there is exactly one merge base. You can leave 55 out at most one of __ and __, in which case it defaults to `HEAD`. 56 57 `-c `:: 58 `--create `:: 59 Create a new branch named __ starting at 60 __ before switching to the branch. This is the 61 transactional equivalent of 62 + 63 ------------ 64 $ git branch 65 $ git switch 66 ------------ 67 + 68 that is to say, the branch is not reset/created unless `git switch` is 69 successful (e.g., when the branch is in use in another worktree, not 70 just the current branch stays the same, but the branch is not reset to 71 the start-point, either). 72 73 `-C `:: 74 `--force-create `:: 75 Similar to `--create` except that if __ already 76 exists, it will be reset to __. This is a 77 convenient shortcut for: 78 + 79 ------------ 80 $ git branch -f __ 81 $ git switch __ 82 ------------ 83 84 `-d`:: 85 `--detach`:: 86 Switch to a commit for inspection and discardable 87 experiments. See the "DETACHED HEAD" section in 88 linkgit:git-checkout[1] for details. 89 90 `--guess`:: 91 `--no-guess`:: 92 If __ is not found but there does exist a tracking 93 branch in exactly one remote (call it __) with a 94 matching name, treat as equivalent to 95 + 96 ------------ 97 $ git switch -c --track / 98 ------------ 99 + 100 If the branch exists in multiple remotes and one of them is named by 101 the `checkout.defaultRemote` configuration variable, we'll use that 102 one for the purposes of disambiguation, even if the __ isn't 103 unique across all remotes. Set it to e.g. `checkout.defaultRemote=origin` 104 to always checkout remote branches from there if __ is 105 ambiguous but exists on the 'origin' remote. See also 106 `checkout.defaultRemote` in linkgit:git-config[1]. 107 + 108 `--guess` is the default behavior. Use `--no-guess` to disable it. 109 + 110 The default behavior can be set via the `checkout.guess` configuration 111 variable. 112 113 `-f`:: 114 `--force`:: 115 An alias for `--discard-changes`. 116 117 `--discard-changes`:: 118 Proceed even if the index or the working tree differs from 119 `HEAD`. Both the index and working tree are restored to match 120 the switching target. If `--recurse-submodules` is specified, 121 submodule content is also restored to match the switching 122 target. This is used to throw away local changes. 123 124 `-m`:: 125 `--merge`:: 126 If you have local modifications to one or more files that 127 are different between the current branch and the branch to 128 which you are switching, the command normally refuses to 129 switch branches in order to preserve your modifications in 130 context. However, with this option, the conflicting local 131 changes are automatically stashed before the switch and 132 reapplied afterwards. If the local changes do not overlap 133 with the differences between branches, the switch proceeds 134 without stashing. If reapplying the stash results in 135 conflicts, the entry is saved to the stash list. Resolve 136 the conflicts and run `git stash drop` when done, or clear 137 the working tree (e.g. with `git reset --hard`) before 138 running `git stash pop` later to re-apply your changes. 139 140 `--conflict=