Skip to content

Commit

Permalink
doc: promote "git switch"
Browse files Browse the repository at this point in the history
The new command "git switch" is added to avoid the confusion of
one-command-do-all "git checkout" for new users. They are also helpful
to avoid ambiguation context.

For these reasons, promote it everywhere possible. This includes
documentation, suggestions/advice from other commands...

The "Checking out files" progress line in unpack-trees.c is also updated
to "Updating files" to be neutral to both git-checkout and git-switch.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
pclouds authored and gitster committed Apr 2, 2019
1 parent ae36fe6 commit 328c6cb
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 105 deletions.
12 changes: 6 additions & 6 deletions Documentation/git-branch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The command's second form creates a new branch head named <branchname>
which points to the current `HEAD`, or <start-point> if given.

Note that this will create the new branch, but it will not switch the
working tree to it; use "git checkout <newbranch>" to switch to the
working tree to it; use "git switch <newbranch>" to switch to the
new branch.

When a local branch is started off a remote-tracking branch, Git sets up the
Expand Down Expand Up @@ -198,7 +198,7 @@ This option is only applicable in non-verbose mode.
+
This behavior is the default when the start point is a remote-tracking branch.
Set the branch.autoSetupMerge configuration variable to `false` if you
want `git checkout` and `git branch` to always behave as if `--no-track`
want `git switch`, `git checkout` and `git branch` to always behave as if `--no-track`
were given. Set it to `always` if you want this behavior when the
start-point is either a local or remote-tracking branch.

Expand Down Expand Up @@ -297,7 +297,7 @@ Start development from a known tag::
$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
$ cd my2.6
$ git branch my2.6.14 v2.6.14 <1>
$ git checkout my2.6.14
$ git switch my2.6.14
------------
+
<1> This step and the next one could be combined into a single step with
Expand All @@ -322,9 +322,9 @@ $ git branch -D test <2>
NOTES
-----

If you are creating a branch that you want to checkout immediately, it is
easier to use the git checkout command with its `-b` option to create
a branch and check it out with a single command.
If you are creating a branch that you want to switch to immediately,
it is easier to use the "git switch" command with its `-c` option to
do the same thing with a single command.

The options `--contains`, `--no-contains`, `--merged` and `--no-merged`
serve four related but different purposes:
Expand Down
3 changes: 2 additions & 1 deletion Documentation/git-check-ref-format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ but it is explicitly forbidden at the beginning of a branch name).
When run with `--branch` option in a repository, the input is first
expanded for the ``previous checkout syntax''
`@{-n}`. For example, `@{-1}` is a way to refer the last thing that
was checked out using "git checkout" operation. This option should be
was checked out using "git switch" or "git checkout" operation.
This option should be
used by porcelains to accept this syntax anywhere a branch name is
expected, so they can act as if you typed the branch name. As an
exception note that, the ``previous checkout operation'' might result
Expand Down
2 changes: 1 addition & 1 deletion Documentation/git-format-patch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ One way to test if your MUA is set up correctly is:
* Apply it:

$ git fetch <project> master:test-apply
$ git checkout test-apply
$ git switch test-apply
$ git reset --hard
$ git am a.patch

Expand Down
2 changes: 1 addition & 1 deletion Documentation/git-merge-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ instead.
Discussion on fork-point mode
-----------------------------

After working on the `topic` branch created with `git checkout -b
After working on the `topic` branch created with `git switch -c
topic origin/master`, the history of remote-tracking branch
`origin/master` may have been rewound and rebuilt, leading to a
history of this shape:
Expand Down
2 changes: 1 addition & 1 deletion Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SYNOPSIS
DESCRIPTION
-----------
If <branch> is specified, 'git rebase' will perform an automatic
`git checkout <branch>` before doing anything else. Otherwise
`git switch <branch>` before doing anything else. Otherwise
it remains on the current branch.

If <upstream> is not specified, the upstream configured in
Expand Down
2 changes: 1 addition & 1 deletion Documentation/git-remote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ $ git branch -r
staging/master
staging/staging-linus
staging/staging-next
$ git checkout -b staging staging/master
$ git switch -c staging staging/master
...
------------

Expand Down
10 changes: 5 additions & 5 deletions Documentation/git-rerere.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ For such a test, you need to merge master and topic somehow.
One way to do it is to pull master into the topic branch:

------------
$ git checkout topic
$ git switch topic
$ git merge master

o---*---o---+ topic
Expand All @@ -113,10 +113,10 @@ the upstream might have been advanced since the test merge `+`,
in which case the final commit graph would look like this:

------------
$ git checkout topic
$ git switch topic
$ git merge master
$ ... work on both topic and master branches
$ git checkout master
$ git switch master
$ git merge topic

o---*---o---+---o---o topic
Expand All @@ -136,11 +136,11 @@ merges, you could blow away the test merge, and keep building on
top of the tip before the test merge:

------------
$ git checkout topic
$ git switch topic
$ git merge master
$ git reset --hard HEAD^ ;# rewind the test merge
$ ... work on both topic and master branches
$ git checkout master
$ git switch master
$ git merge topic

o---*---o-------o---o topic
Expand Down
20 changes: 10 additions & 10 deletions Documentation/git-reset.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ See also the `--amend` option to linkgit:git-commit[1].
Undo a commit, making it a topic branch::
+
------------
$ git branch topic/wip <1>
$ git reset --hard HEAD~3 <2>
$ git checkout topic/wip <3>
$ git branch topic/wip <1>
$ git reset --hard HEAD~3 <2>
$ git switch topic/wip <3>
------------
+
<1> You have made some commits, but realize they were premature
Expand Down Expand Up @@ -232,13 +232,13 @@ working tree are not in any shape to be committed yet, but you
need to get to the other branch for a quick bugfix.
+
------------
$ git checkout feature ;# you were working in "feature" branch and
$ work work work ;# got interrupted
$ git switch feature ;# you were working in "feature" branch and
$ work work work ;# got interrupted
$ git commit -a -m "snapshot WIP" <1>
$ git checkout master
$ git switch master
$ fix fix fix
$ git commit ;# commit with real log
$ git checkout feature
$ git switch feature
$ git reset --soft HEAD^ ;# go back to WIP state <2>
$ git reset <3>
------------
Expand Down Expand Up @@ -279,18 +279,18 @@ reset it while keeping the changes in your working tree.
+
------------
$ git tag start
$ git checkout -b branch1
$ git switch -c branch1
$ edit
$ git commit ... <1>
$ edit
$ git checkout -b branch2 <2>
$ git switch -c branch2 <2>
$ git reset --keep start <3>
------------
+
<1> This commits your first edits in `branch1`.
<2> In the ideal world, you could have realized that the earlier
commit did not belong to the new topic when you created and switched
to `branch2` (i.e. `git checkout -b branch2 start`), but nobody is
to `branch2` (i.e. `git switch -c branch2 start`), but nobody is
perfect.
<3> But you can use `reset --keep` to remove the unwanted commit after
you switched to `branch2`.
Expand Down
9 changes: 5 additions & 4 deletions Documentation/git-stash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ return to your original branch to make the emergency fix, like this:
+
----------------------------------------------------------------
# ... hack hack hack ...
$ git checkout -b my_wip
$ git switch -c my_wip
$ git commit -a -m "WIP"
$ git checkout master
$ git switch master
$ edit emergency fix
$ git commit -a -m "Fix in a hurry"
$ git checkout my_wip
$ git switch my_wip
$ git reset --soft HEAD^
# ... continue hacking ...
----------------------------------------------------------------
Expand Down Expand Up @@ -293,7 +293,8 @@ SEE ALSO
linkgit:git-checkout[1],
linkgit:git-commit[1],
linkgit:git-reflog[1],
linkgit:git-reset[1]
linkgit:git-reset[1],
linkgit:git-switch[1]

GIT
---
Expand Down
19 changes: 9 additions & 10 deletions Documentation/gitcore-tutorial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ used earlier, and create a branch in it. You do that by simply just
saying that you want to check out a new branch:

------------
$ git checkout -b mybranch
$ git switch -c mybranch
------------

will create a new branch based at the current `HEAD` position, and switch
Expand All @@ -755,7 +755,7 @@ just telling 'git checkout' what the base of the checkout would be.
In other words, if you have an earlier tag or branch, you'd just do

------------
$ git checkout -b mybranch earlier-commit
$ git switch -c mybranch earlier-commit
------------

and it would create the new branch `mybranch` at the earlier commit,
Expand All @@ -765,7 +765,7 @@ and check out the state at that time.
You can always just jump back to your original `master` branch by doing

------------
$ git checkout master
$ git switch master
------------

(or any other branch-name, for that matter) and if you forget which
Expand Down Expand Up @@ -794,7 +794,7 @@ $ git branch <branchname> [startingpoint]

which will simply _create_ the branch, but will not do anything further.
You can then later -- once you decide that you want to actually develop
on that branch -- switch to that branch with a regular 'git checkout'
on that branch -- switch to that branch with a regular 'git switch'
with the branchname as the argument.


Expand All @@ -808,7 +808,7 @@ being the same as the original `master` branch, let's make sure we're in
that branch, and do some work there.

------------------------------------------------
$ git checkout mybranch
$ git switch mybranch
$ echo "Work, work, work" >>hello
$ git commit -m "Some work." -i hello
------------------------------------------------
Expand All @@ -825,7 +825,7 @@ does some work in the original branch, and simulate that by going back
to the master branch, and editing the same file differently there:

------------
$ git checkout master
$ git switch master
------------

Here, take a moment to look at the contents of `hello`, and notice how they
Expand Down Expand Up @@ -958,7 +958,7 @@ to the `master` branch. Let's go back to `mybranch`, and run
'git merge' to get the "upstream changes" back to your branch.

------------
$ git checkout mybranch
$ git switch mybranch
$ git merge -m "Merge upstream changes." master
------------

Expand Down Expand Up @@ -1133,9 +1133,8 @@ Remember, before running 'git merge', our `master` head was at
work." commit.

------------
$ git checkout mybranch
$ git reset --hard master^2
$ git checkout master
$ git switch -C mybranch master^2
$ git switch master
$ git reset --hard master^
------------

Expand Down
24 changes: 12 additions & 12 deletions Documentation/giteveryday.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ following commands.

* linkgit:git-log[1] to see what happened.

* linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
* linkgit:git-switch[1] and linkgit:git-branch[1] to switch
branches.

* linkgit:git-add[1] to manage the index file.
Expand Down Expand Up @@ -80,7 +80,7 @@ $ git tag v2.43 <2>
Create a topic branch and develop.::
+
------------
$ git checkout -b alsa-audio <1>
$ git switch -c alsa-audio <1>
$ edit/compile/test
$ git checkout -- curses/ux_audio_oss.c <2>
$ git add curses/ux_audio_alsa.c <3>
Expand All @@ -90,7 +90,7 @@ $ git commit -a -s <5>
$ edit/compile/test
$ git diff HEAD^ <6>
$ git commit -a --amend <7>
$ git checkout master <8>
$ git switch master <8>
$ git merge alsa-audio <9>
$ git log --since='3 days ago' <10>
$ git log v2.43.. curses/ <11>
Expand Down Expand Up @@ -148,11 +148,11 @@ Clone the upstream and work on it. Feed changes to upstream.::
------------
$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
$ cd my2.6
$ git checkout -b mine master <1>
$ git switch -c mine master <1>
$ edit/compile/test; git commit -a -s <2>
$ git format-patch master <3>
$ git send-email --to="person <email@example.com>" 00*.patch <4>
$ git checkout master <5>
$ git switch master <5>
$ git pull <6>
$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <7>
$ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git <8>
Expand Down Expand Up @@ -194,7 +194,7 @@ satellite$ edit/compile/test/commit
satellite$ git push origin <4>

mothership$ cd frotz
mothership$ git checkout master
mothership$ git switch master
mothership$ git merge satellite/master <5>
------------
+
Expand All @@ -216,7 +216,7 @@ machine into the master branch.
Branch off of a specific tag.::
+
------------
$ git checkout -b private2.6.14 v2.6.14 <1>
$ git switch -c private2.6.14 v2.6.14 <1>
$ edit/compile/test; git commit -a
$ git checkout master
$ git cherry-pick v2.6.14..private2.6.14 <2>
Expand Down Expand Up @@ -274,14 +274,14 @@ $ mailx <3>
& s 2 3 4 5 ./+to-apply
& s 7 8 ./+hold-linus
& q
$ git checkout -b topic/one master
$ git switch -c topic/one master
$ git am -3 -i -s ./+to-apply <4>
$ compile/test
$ git checkout -b hold/linus && git am -3 -i -s ./+hold-linus <5>
$ git checkout topic/one && git rebase master <6>
$ git checkout pu && git reset --hard next <7>
$ git switch -c hold/linus && git am -3 -i -s ./+hold-linus <5>
$ git switch topic/one && git rebase master <6>
$ git switch -C pu next <7>
$ git merge topic/one topic/two && git merge hold/linus <8>
$ git checkout maint
$ git switch maint
$ git cherry-pick master~4 <9>
$ compile/test
$ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
Expand Down
4 changes: 2 additions & 2 deletions Documentation/gittutorial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ automatically. The asterisk marks the branch you are currently on;
type

------------------------------------------------
$ git checkout experimental
$ git switch experimental
------------------------------------------------

to switch to the experimental branch. Now edit a file, commit the
Expand All @@ -216,7 +216,7 @@ change, and switch back to the master branch:
------------------------------------------------
(edit file)
$ git commit -a
$ git checkout master
$ git switch master
------------------------------------------------

Check that the change you made is no longer visible, since it was
Expand Down
3 changes: 1 addition & 2 deletions Documentation/gitworkflows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ topics on 'next':
.Rewind and rebuild next
[caption="Recipe: "]
=====================================
* `git checkout next`
* `git reset --hard master`
* `git switch -C next master`
* `git merge ai/topic_in_next1`
* `git merge ai/topic_in_next2`
* ...
Expand Down
2 changes: 1 addition & 1 deletion Documentation/revisions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Here's an example to make it more clear:
------------------------------
$ git config push.default current
$ git config remote.pushdefault myfork
$ git checkout -b mybranch origin/master
$ git switch -c mybranch origin/master

$ git rev-parse --symbolic-full-name @{upstream}
refs/remotes/origin/master
Expand Down
Loading

0 comments on commit 328c6cb

Please sign in to comment.