'\" t .\" Title: git-switch .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 02/22/2023 .\" Manual: Git Manual .\" Source: Git 2.30.2 .\" Language: English .\" .TH "GIT\-SWITCH" "1" "02/22/2023" "Git 2\&.30\&.2" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-switch \- Switch branches .SH "SYNOPSIS" .sp .nf \fIgit switch\fR [] [\-\-no\-guess] \fIgit switch\fR [] \-\-detach [] \fIgit switch\fR [] (\-c|\-C) [] \fIgit switch\fR [] \-\-orphan .fi .sp .SH "DESCRIPTION" .sp 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\&. .sp 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\&. .sp 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\&. .sp THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&. .SH "OPTIONS" .PP .RS 4 Branch to switch to\&. .RE .PP .RS 4 Name for the new branch\&. .RE .PP .RS 4 The starting point for the new branch\&. Specifying a \fB\fR allows you to create a branch based on some other point in history than where HEAD currently points\&. (Or, in the case of \fB\-\-detach\fR, allows you to inspect and detach from some other point\&.) .sp You can use the \fB@{\-N}\fR syntax to refer to the N\-th last branch/commit switched to using "git switch" or "git checkout" operation\&. You may also specify \fB\-\fR which is synonymous to \fB@{\-1}\fR\&. This is often used to switch quickly between two branches, or to undo a branch switch by mistake\&. .sp As a special case, you may use \fBA\&.\&.\&.B\fR as a shortcut for the merge base of \fBA\fR and \fBB\fR if there is exactly one merge base\&. You can leave out at most one of \fBA\fR and \fBB\fR, in which case it defaults to \fBHEAD\fR\&. .RE .PP \-c , \-\-create .RS 4 Create a new branch named \fB\fR starting at \fB\fR before switching to the branch\&. This is a convenient shortcut for: .sp .if n \{\ .RS 4 .\} .nf $ git branch $ git switch .fi .if n \{\ .RE .\} .sp .RE .PP \-C , \-\-force\-create .RS 4 Similar to \fB\-\-create\fR except that if \fB\fR already exists, it will be reset to \fB\fR\&. This is a convenient shortcut for: .sp .if n \{\ .RS 4 .\} .nf $ git branch \-f $ git switch .fi .if n \{\ .RE .\} .sp .RE .PP \-d, \-\-detach .RS 4 Switch to a commit for inspection and discardable experiments\&. See the "DETACHED HEAD" section in \fBgit-checkout\fR(1) for details\&. .RE .PP \-\-guess, \-\-no\-guess .RS 4 If \fB\fR is not found but there does exist a tracking branch in exactly one remote (call it \fB\fR) with a matching name, treat as equivalent to .sp .if n \{\ .RS 4 .\} .nf $ git switch \-c \-\-track / .fi .if n \{\ .RE .\} .sp If the branch exists in multiple remotes and one of them is named by the \fBcheckout\&.defaultRemote\fR configuration variable, we\(cqll use that one for the purposes of disambiguation, even if the \fB\fR isn\(cqt unique across all remotes\&. Set it to e\&.g\&. \fBcheckout\&.defaultRemote=origin\fR to always checkout remote branches from there if \fB\fR is ambiguous but exists on the \fIorigin\fR remote\&. See also \fBcheckout\&.defaultRemote\fR in \fBgit-config\fR(1)\&. .sp \fB\-\-guess\fR is the default behavior\&. Use \fB\-\-no\-guess\fR to disable it\&. .sp The default behavior can be set via the \fBcheckout\&.guess\fR configuration variable\&. .RE .PP \-f, \-\-force .RS 4 An alias for \fB\-\-discard\-changes\fR\&. .RE .PP \-\-discard\-changes .RS 4 Proceed even if the index or the working tree differs from \fBHEAD\fR\&. Both the index and working tree are restored to match the switching target\&. If \fB\-\-recurse\-submodules\fR is specified, submodule content is also restored to match the switching target\&. This is used to throw away local changes\&. .RE .PP \-m, \-\-merge .RS 4 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\&. .sp 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 \fBgit add\fR (or \fBgit rm\fR if the merge should result in deletion of the path)\&. .RE .PP \-\-conflict=