logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-switch.1 (13578B)


  1. '\" t
  2. .\" Title: git-switch
  3. .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-SWITCH" "1" "2025-03-14" "Git 2\&.49\&.0" "Git Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-switch \- Switch branches
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit switch\fR [<options>] [\-\-no\-guess] <branch>
  36. \fIgit switch\fR [<options>] \-\-detach [<start\-point>]
  37. \fIgit switch\fR [<options>] (\-c|\-C) <new\-branch> [<start\-point>]
  38. \fIgit switch\fR [<options>] \-\-orphan <new\-branch>
  39. .fi
  40. .SH "DESCRIPTION"
  41. .sp
  42. 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\&.
  43. .sp
  44. Optionally a new branch could be created with either \fB\-c\fR, \fB\-C\fR, automatically from a remote branch of same name (see \fB\-\-guess\fR), or detach the working tree from any branch with \fB\-\-detach\fR, along with switching\&.
  45. .sp
  46. Switching branches does not require a clean index and working tree (i\&.e\&. no differences compared to \fBHEAD\fR)\&. The operation is aborted however if the operation leads to loss of local changes, unless told otherwise with \fB\-\-discard\-changes\fR or \fB\-\-merge\fR\&.
  47. .sp
  48. THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&.
  49. .SH "OPTIONS"
  50. .PP
  51. <branch>
  52. .RS 4
  53. Branch to switch to\&.
  54. .RE
  55. .PP
  56. <new\-branch>
  57. .RS 4
  58. Name for the new branch\&.
  59. .RE
  60. .PP
  61. <start\-point>
  62. .RS 4
  63. The starting point for the new branch\&. Specifying a
  64. \fI<start\-point>\fR
  65. allows you to create a branch based on some other point in history than where HEAD currently points\&. (Or, in the case of
  66. \fB\-\-detach\fR, allows you to inspect and detach from some other point\&.)
  67. .sp
  68. You can use the
  69. \fB@\fR{\-N} syntax to refer to the N\-th last branch/commit switched to using "git switch" or "git checkout" operation\&. You may also specify
  70. \fB\-\fR
  71. which is synonymous to
  72. \fB@\fR{\-1}\&. This is often used to switch quickly between two branches, or to undo a branch switch by mistake\&.
  73. .sp
  74. As a special case, you may use
  75. \fBA\fR\fB\&.\&.\&.\fR\fBB\fR
  76. as a shortcut for the merge base of
  77. \fBA\fR
  78. and
  79. \fBB\fR
  80. if there is exactly one merge base\&. You can leave out at most one of
  81. \fBA\fR
  82. and
  83. \fBB\fR, in which case it defaults to
  84. \fBHEAD\fR\&.
  85. .RE
  86. .PP
  87. \-c <new\-branch>, \-\-create <new\-branch>
  88. .RS 4
  89. Create a new branch named
  90. \fI<new\-branch>\fR
  91. starting at
  92. \fI<start\-point>\fR
  93. before switching to the branch\&. This is the transactional equivalent of
  94. .sp
  95. .if n \{\
  96. .RS 4
  97. .\}
  98. .nf
  99. $ git branch <new\-branch>
  100. $ git switch <new\-branch>
  101. .fi
  102. .if n \{\
  103. .RE
  104. .\}
  105. .sp
  106. 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)\&.
  107. .RE
  108. .PP
  109. \-C <new\-branch>, \-\-force\-create <new\-branch>
  110. .RS 4
  111. Similar to
  112. \fB\-\-create\fR
  113. except that if
  114. \fI<new\-branch>\fR
  115. already exists, it will be reset to
  116. \fI<start\-point>\fR\&. This is a convenient shortcut for:
  117. .sp
  118. .if n \{\
  119. .RS 4
  120. .\}
  121. .nf
  122. $ git branch \-f <new\-branch>
  123. $ git switch <new\-branch>
  124. .fi
  125. .if n \{\
  126. .RE
  127. .\}
  128. .RE
  129. .PP
  130. \-d, \-\-detach
  131. .RS 4
  132. Switch to a commit for inspection and discardable experiments\&. See the "DETACHED HEAD" section in
  133. \fBgit-checkout\fR(1)
  134. for details\&.
  135. .RE
  136. .PP
  137. \-\-guess, \-\-no\-guess
  138. .RS 4
  139. If
  140. \fI<branch>\fR
  141. is not found but there does exist a tracking branch in exactly one remote (call it
  142. \fI<remote>\fR) with a matching name, treat as equivalent to
  143. .sp
  144. .if n \{\
  145. .RS 4
  146. .\}
  147. .nf
  148. $ git switch \-c <branch> \-\-track <remote>/<branch>
  149. .fi
  150. .if n \{\
  151. .RE
  152. .\}
  153. .sp
  154. If the branch exists in multiple remotes and one of them is named by the
  155. \fBcheckout\&.defaultRemote\fR
  156. configuration variable, we\(cqll use that one for the purposes of disambiguation, even if the
  157. \fI<branch>\fR
  158. isn\(cqt unique across all remotes\&. Set it to e\&.g\&.
  159. \fBcheckout\&.defaultRemote=origin\fR
  160. to always checkout remote branches from there if
  161. \fI<branch>\fR
  162. is ambiguous but exists on the
  163. \fIorigin\fR
  164. remote\&. See also
  165. \fBcheckout\&.defaultRemote\fR
  166. in
  167. \fBgit-config\fR(1)\&.
  168. .sp
  169. \fB\-\-guess\fR
  170. is the default behavior\&. Use
  171. \fB\-\-no\-guess\fR
  172. to disable it\&.
  173. .sp
  174. The default behavior can be set via the
  175. \fBcheckout\&.guess\fR
  176. configuration variable\&.
  177. .RE
  178. .PP
  179. \-f, \-\-force
  180. .RS 4
  181. An alias for
  182. \fB\-\-discard\-changes\fR\&.
  183. .RE
  184. .PP
  185. \-\-discard\-changes
  186. .RS 4
  187. Proceed even if the index or the working tree differs from
  188. \fBHEAD\fR\&. Both the index and working tree are restored to match the switching target\&. If
  189. \fB\-\-recurse\-submodules\fR
  190. is specified, submodule content is also restored to match the switching target\&. This is used to throw away local changes\&.
  191. .RE
  192. .PP
  193. \-m, \-\-merge
  194. .RS 4
  195. 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\&.
  196. .sp
  197. 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
  198. \fBgit\fR
  199. \fBadd\fR
  200. (or
  201. \fBgit\fR
  202. \fBrm\fR
  203. if the merge should result in deletion of the path)\&.
  204. .RE
  205. .PP
  206. \-\-conflict=<style>
  207. .RS 4
  208. The same as
  209. \fB\-\-merge\fR
  210. option above, but changes the way the conflicting hunks are presented, overriding the
  211. \fBmerge\&.conflictStyle\fR
  212. configuration variable\&. Possible values are "merge" (default), "diff3", and "zdiff3"\&.
  213. .RE
  214. .PP
  215. \-q, \-\-quiet
  216. .RS 4
  217. Quiet, suppress feedback messages\&.
  218. .RE
  219. .PP
  220. \-\-progress, \-\-no\-progress
  221. .RS 4
  222. Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
  223. \fB\-\-quiet\fR
  224. is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
  225. \fB\-\-quiet\fR\&.
  226. .RE
  227. .PP
  228. \-t, \-\-track [direct|inherit]
  229. .RS 4
  230. When creating a new branch, set up "upstream" configuration\&.
  231. \fB\-c\fR
  232. is implied\&. See
  233. \fB\-\-track\fR
  234. in
  235. \fBgit-branch\fR(1)
  236. for details\&.
  237. .sp
  238. If no
  239. \fB\-c\fR
  240. 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
  241. \fBhack\fR
  242. as the local branch when branching off of
  243. \fBorigin/hack\fR
  244. (or
  245. \fBremotes/origin/hack\fR, or even
  246. \fBrefs/remotes/origin/hack\fR)\&. 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
  247. \fB\-c\fR
  248. in such a case\&.
  249. .RE
  250. .PP
  251. \-\-no\-track
  252. .RS 4
  253. Do not set up "upstream" configuration, even if the
  254. \fBbranch\&.autoSetupMerge\fR
  255. configuration variable is true\&.
  256. .RE
  257. .PP
  258. \-\-orphan <new\-branch>
  259. .RS 4
  260. Create a new unborn branch, named
  261. \fI<new\-branch>\fR\&. All tracked files are removed\&.
  262. .RE
  263. .PP
  264. \-\-ignore\-other\-worktrees
  265. .RS 4
  266. \fBgit\fR
  267. \fBswitch\fR
  268. 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\&.
  269. .RE
  270. .PP
  271. \-\-recurse\-submodules, \-\-no\-recurse\-submodules
  272. .RS 4
  273. Using
  274. \fB\-\-recurse\-submodules\fR
  275. will update the content of all active submodules according to the commit recorded in the superproject\&. If nothing (or
  276. \fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
  277. \fBgit-submodule\fR(1), this will detach
  278. \fBHEAD\fR
  279. of the submodules\&.
  280. .RE
  281. .SH "EXAMPLES"
  282. .sp
  283. The following command switches to the "master" branch:
  284. .sp
  285. .if n \{\
  286. .RS 4
  287. .\}
  288. .nf
  289. $ git switch master
  290. .fi
  291. .if n \{\
  292. .RE
  293. .\}
  294. .sp
  295. After working in the wrong branch, switching to the correct branch would be done using:
  296. .sp
  297. .if n \{\
  298. .RS 4
  299. .\}
  300. .nf
  301. $ git switch mytopic
  302. .fi
  303. .if n \{\
  304. .RE
  305. .\}
  306. .sp
  307. 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:
  308. .sp
  309. .if n \{\
  310. .RS 4
  311. .\}
  312. .nf
  313. $ git switch mytopic
  314. error: You have local changes to \*(Aqfrotz\*(Aq; not switching branches\&.
  315. .fi
  316. .if n \{\
  317. .RE
  318. .\}
  319. .sp
  320. You can give the \fB\-m\fR flag to the command, which would try a three\-way merge:
  321. .sp
  322. .if n \{\
  323. .RS 4
  324. .\}
  325. .nf
  326. $ git switch \-m mytopic
  327. Auto\-merging frotz
  328. .fi
  329. .if n \{\
  330. .RE
  331. .\}
  332. .sp
  333. After this three\-way merge, the local modifications are \fInot\fR registered in your index file, so \fBgit\fR \fBdiff\fR would show you what changes you made since the tip of the new branch\&.
  334. .sp
  335. To switch back to the previous branch before we switched to mytopic (i\&.e\&. "master" branch):
  336. .sp
  337. .if n \{\
  338. .RS 4
  339. .\}
  340. .nf
  341. $ git switch \-
  342. .fi
  343. .if n \{\
  344. .RE
  345. .\}
  346. .sp
  347. You can grow a new branch from any commit\&. For example, switch to "HEAD~3" and create branch "fixup":
  348. .sp
  349. .if n \{\
  350. .RS 4
  351. .\}
  352. .nf
  353. $ git switch \-c fixup HEAD~3
  354. Switched to a new branch \*(Aqfixup\*(Aq
  355. .fi
  356. .if n \{\
  357. .RE
  358. .\}
  359. .sp
  360. If you want to start a new branch from a remote branch of the same name:
  361. .sp
  362. .if n \{\
  363. .RS 4
  364. .\}
  365. .nf
  366. $ git switch new\-topic
  367. Branch \*(Aqnew\-topic\*(Aq set up to track remote branch \*(Aqnew\-topic\*(Aq from \*(Aqorigin\*(Aq
  368. Switched to a new branch \*(Aqnew\-topic\*(Aq
  369. .fi
  370. .if n \{\
  371. .RE
  372. .\}
  373. .sp
  374. To check out commit \fBHEAD~3\fR for temporary inspection or experiment without creating a new branch:
  375. .sp
  376. .if n \{\
  377. .RS 4
  378. .\}
  379. .nf
  380. $ git switch \-\-detach HEAD~3
  381. HEAD is now at 9fc9555312 Merge branch \*(Aqcc/shared\-index\-permbits\*(Aq
  382. .fi
  383. .if n \{\
  384. .RE
  385. .\}
  386. .sp
  387. If it turns out whatever you have done is worth keeping, you can always create a new name for it (without switching away):
  388. .sp
  389. .if n \{\
  390. .RS 4
  391. .\}
  392. .nf
  393. $ git switch \-c good\-surprises
  394. .fi
  395. .if n \{\
  396. .RE
  397. .\}
  398. .SH "CONFIGURATION"
  399. .sp
  400. Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
  401. .PP
  402. checkout\&.defaultRemote
  403. .RS 4
  404. When you run
  405. \fBgit\fR
  406. \fBcheckout\fR
  407. \fI<something>\fR
  408. or
  409. \fBgit\fR
  410. \fBswitch\fR
  411. \fI<something>\fR
  412. and only have one remote, it may implicitly fall back on checking out and tracking e\&.g\&.
  413. \fBorigin/\fR\fI<something>\fR\&. This stops working as soon as you have more than one remote with a
  414. \fI<something>\fR
  415. 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
  416. \fBorigin\fR\&.
  417. .sp
  418. Currently this is used by
  419. \fBgit-switch\fR(1)
  420. and
  421. \fBgit-checkout\fR(1)
  422. when
  423. \fBgit\fR
  424. \fBcheckout\fR
  425. \fI<something>\fR
  426. or
  427. \fBgit\fR
  428. \fBswitch\fR
  429. \fI<something>\fR
  430. will checkout the
  431. \fI<something>\fR
  432. branch on another remote, and by
  433. \fBgit-worktree\fR(1)
  434. when
  435. \fBgit\fR
  436. \fBworktree\fR
  437. \fBadd\fR
  438. refers to a remote branch\&. This setting might be used for other checkout\-like commands or functionality in the future\&.
  439. .RE
  440. .PP
  441. checkout\&.guess
  442. .RS 4
  443. Provides the default value for the
  444. \fB\-\-guess\fR
  445. or
  446. \fB\-\-no\-guess\fR
  447. option in
  448. \fBgit\fR
  449. \fBcheckout\fR
  450. and
  451. \fBgit\fR
  452. \fBswitch\fR\&. See
  453. \fBgit-switch\fR(1)
  454. and
  455. \fBgit-checkout\fR(1)\&.
  456. .RE
  457. .PP
  458. checkout\&.workers
  459. .RS 4
  460. 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
  461. \fBcheckout\&.thresholdForParallelism\fR
  462. affect all commands that perform checkout\&. E\&.g\&. checkout, clone, reset, sparse\-checkout, etc\&.
  463. .sp
  464. 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\&.
  465. .RE
  466. .PP
  467. checkout\&.thresholdForParallelism
  468. .RS 4
  469. 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\&.
  470. .RE
  471. .SH "SEE ALSO"
  472. .sp
  473. \fBgit-checkout\fR(1), \fBgit-branch\fR(1)
  474. .SH "GIT"
  475. .sp
  476. Part of the \fBgit\fR(1) suite