git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/5] doc: git-checkout: clarify `git checkout <branch>`

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 26, 2025, 21:38 UTC
Message-ID
<xmqqldn5ix0r.fsf@gitster.g>
In-Reply-To
<b8873c4529caeddc85879efd122e5a57278352f0.1756148933.git.gitgitgadget@gmail.com>
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 36 quoted lines
> From: Julia Evans <julia@jvns.ca>
>
> - "To prepare for working on _<branch>_..." is confusing to some users:
>   it makes it sound like these are steps that the user has to do, not
>   steps that Git itself will do. Reword it.
> - Use "changes" instead of "modifications" (which Git normally does)
> - Mention that `git checkout` will fail if there's a merge conflict
> - The current explanation of `You could omit <branch>`... is confusing
>   to users (what are the "expensive side effects"? what's a better way
>   of getting the same info?). Be more direct and mention that `git
>   status` is likely a better option.
>
> Signed-off-by: Julia Evans <julia@jvns.ca>
> ---
>  Documentation/git-checkout.adoc | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/git-checkout.adoc b/Documentation/git-checkout.adoc
> index ddda891c0ff7..a3edb95973a2 100644
> --- a/Documentation/git-checkout.adoc
> +++ b/Documentation/git-checkout.adoc
> @@ -30,11 +30,12 @@ See ARGUMENT DISAMBIGUATION below for how Git decides which one to do.
>  Here's a description of all of the modes:
>  
>  `git checkout [<branch>]`::
> -	To prepare for working on _<branch>_, switch to it by updating
> -	the index and the files in the working tree, and by pointing
> -	`HEAD` at the branch. Local modifications to the files in the
> -	working tree are kept, so that they can be committed to the
> -	_<branch>_.
> +	Switch to _<branch>_. This will update the files in the working tree,
> +	point `HEAD` at the branch, and update the index. Local changes to
> +	the files in the working tree are kept, so that they can be committed
> +	to the _<branch>_. If the local changes conflict with the changes on
> +	_<branch>_, no changes will be made and the checkout operation will
> +	fail.

Do we expect readers to truly understand what is to "switch to branch" without explanation? IOW, I am undecided if the lost "To prepare for working on" is a good thing.

Usually with "changes on _<branch>_", people mean quite a different thing from what the above paragraph refers to.

Imagine that you are on a branch that you forked from 'main' some time ago, built a handful of commits, among which there may be ones that touch file F. You further have local modification to file F. Now you want to switch to another branch. That branch, since it forked from 'main', never touched F. Your local changes do not conflict with "the changes on branch" (there is no changes on branch to conflict with your work, as F stayed the same).

To improve, "with the changes on _<branch>_" should be phrased more like "with the differences between the current state and that of the _<branch>_" or something.

Show 14 quoted lines
>  +
>  If _<branch>_ is not found but there does exist a tracking branch in
>  exactly one remote (call it _<remote>_) with a matching name and
> @@ -44,10 +45,9 @@ exactly one remote (call it _<remote>_) with a matching name and
>  $ git checkout -b <branch> --track <remote>/<branch>
>  ------------
>  +
> -You could omit _<branch>_, in which case the command degenerates to
> -"check out the current branch", which is a glorified no-op with
> -rather expensive side-effects to show only the tracking information,
> -if it exists, for the current branch.
> +Running `git checkout` without specifying a branch will output the
> +tracking information, if it exists, for the current branch, but it's
> +slower than getting the same information from `git status`.

I do not think "glorified no-op" is a reference to "status". At least, when I wrote it, I didn't mean it that way to compare this glorified no-op with "git status" [*]. It is a reference to "even though you are invoking the 'checkout' command, you are not checking out anything." The side effect is to see the tracking information, which is "rather expensive side-effects"---compared to doing nothing, anything is expensive ;-).

I strongly suspect that running "git status" is much more costly than "git checkout", simply because the former has to do a lot more than just peeking the tracking information; it internally runs diff between HEAD and the index, and between the index and the working tree, and it also has to find and list untracked paths. Both commands compute the tracking info by calling the same remote.c::format_tracking_info() function.

Other than these minor points, the new text seems a definite improvement.

[References]
 * https://lore.kernel.org/git/7vk3shm5d5.fsf@alter.siamese.dyndns.org/
   is where the "glorified no-op" came from.
Previous: Julia Evans via GitGitGadgetNext: Julia Evans
Message 13 of 68 in “doc: git-checkout: clarify DESCRIPTION section”
  1. 0/5 doc: git-checkout: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 25, 2025
  2. 1/5 doc: git-checkout: clarify introJulia Evans via GitGitGadget, Aug 25, 2025
  3. Junio C HamanoAug 26, 2025
  4. Junio C HamanoAug 26, 2025
  5. Julia EvansAug 26, 2025
  6. D. Ben KnobleAug 28, 2025
  7. Julia EvansAug 28, 2025
  8. Junio C HamanoAug 28, 2025
  9. D. Ben KnobleAug 29, 2025
  10. Junio C HamanoAug 29, 2025
  11. D. Ben KnobleSep 3, 2025
  12. 2/5 doc: git-checkout: clarify `git checkout <branch>`Julia Evans via GitGitGadget, Aug 25, 2025
  13. Junio C HamanoAug 26, 2025
  14. Julia EvansAug 28, 2025
  15. Junio C HamanoAug 28, 2025
  16. Julia EvansAug 28, 2025
  17. 3/5 doc: git-checkout: don't use "reset"Julia Evans via GitGitGadget, Aug 25, 2025
  18. 4/5 doc: git-checkout: deduplicate --detach explanationJulia Evans via GitGitGadget, Aug 25, 2025
  19. 5/5 doc: git-checkout: clarify restoring files sectionJulia Evans via GitGitGadget, Aug 25, 2025
  20. Junio C HamanoAug 26, 2025
  21. Julia EvansAug 28, 2025
  22. D. Ben KnobleAug 28, 2025
  23. Julia EvansAug 28, 2025
  24. Junio C HamanoAug 28, 2025
  25. D. Ben KnobleAug 29, 2025
  26. 0/5 doc: git-checkout: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 29, 2025
  27. 1/5 doc: git-checkout: clarify introJulia Evans via GitGitGadget, Aug 29, 2025
  28. Junio C HamanoAug 29, 2025
  29. Julia EvansSep 2, 2025
  30. 2/5 doc: git-checkout: clarify `git checkout <branch>`Julia Evans via GitGitGadget, Aug 29, 2025
  31. Junio C HamanoAug 29, 2025
  32. Julia EvansSep 2, 2025
  33. 3/5 doc: git-checkout: don't use "reset"Julia Evans via GitGitGadget, Aug 29, 2025
  34. Junio C HamanoAug 29, 2025
  35. Julia EvansSep 1, 2025
  36. Junio C HamanoSep 2, 2025
  37. 4/5 doc: git-checkout: deduplicate --detach explanationJulia Evans via GitGitGadget, Aug 29, 2025
  38. 5/5 doc: git-checkout: clarify restoring files sectionJulia Evans via GitGitGadget, Aug 29, 2025
  39. 0/6 doc: git-checkout: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Sep 3, 2025
  40. 1/6 doc: git-checkout: clarify introJulia Evans via GitGitGadget, Sep 3, 2025
  41. 2/6 doc: git-checkout: clarify `git checkout <branch>`Julia Evans via GitGitGadget, Sep 3, 2025
  42. 3/6 doc: git-checkout: clarify `-b` and `-B`Julia Evans via GitGitGadget, Sep 3, 2025
  43. 4/6 doc: git-checkout: deduplicate --detach explanationJulia Evans via GitGitGadget, Sep 3, 2025
  44. 5/6 doc: git-checkout: split up restoring files sectionJulia Evans via GitGitGadget, Sep 3, 2025
  45. 6/6 doc: git-checkout: clarify restoring files sectionJulia Evans via GitGitGadget, Sep 3, 2025
  46. Junio C HamanoSep 3, 2025
  47. Junio C HamanoSep 3, 2025
  48. Julia EvansSep 3, 2025
  49. 0/7 doc: git-checkout: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Sep 10, 2025
  50. 1/7 doc: git-checkout: clarify intro sentenceJulia Evans via GitGitGadget, Sep 10, 2025
  51. 2/7 doc: git-checkout: clarify ARGUMENT DISAMBIGUATIONJulia Evans via GitGitGadget, Sep 10, 2025
  52. 3/7 doc: git-checkout: clarify `git checkout <branch>`Julia Evans via GitGitGadget, Sep 10, 2025
  53. 4/7 doc: git-checkout: clarify `-b` and `-B`Julia Evans via GitGitGadget, Sep 10, 2025
  54. Kristoffer HaugsbakkSep 29, 2025
  55. doc: git-checkout: fix placeholder markupkristofferhaugsbakk@fastmail.com, Oct 2, 2025
  56. doc: git-checkout: fix placeholder markupkristofferhaugsbakk@fastmail.com, Oct 16, 2025
  57. Julia EvansOct 17, 2025
  58. doc: git-checkout: fix placeholder markupkristofferhaugsbakk@fastmail.com, Oct 17, 2025
  59. 5/7 doc: git-checkout: deduplicate --detach explanationJulia Evans via GitGitGadget, Sep 10, 2025
  60. 6/7 doc: git-checkout: split up restoring files sectionJulia Evans via GitGitGadget, Sep 10, 2025
  61. 7/7 doc: git-checkout: clarify restoring files sectionJulia Evans via GitGitGadget, Sep 10, 2025
  62. Ben KnobleSep 11, 2025
  63. Julia EvansSep 12, 2025
  64. Kristoffer HaugsbakkSep 12, 2025
  65. Junio C HamanoSep 15, 2025
  66. Kristoffer HaugsbakkSep 16, 2025
  67. Junio C HamanoSep 12, 2025
  68. Junio C HamanoSep 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.