Skip to contentSkip to conversation

Documentation: clarify usage of checkout

PATCH In review Chris Rorvick 5 participants 23 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover Documentation: clarify usage of checkout

This is response to the questions posed in:

http://thread.gmane.org/gmane.comp.version-control.git/211624

It doesn't seem like the behavior implemented in 70c9ac2 is documented.

Chris Rorvick (2):
Documentation/git-checkout.txt: clarify usage Documentation/git-checkout.txt: document 70c9ac2 behavior

 Documentation/git-checkout.txt | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.1.rc1.203.g1ddc124
#1 lore raw

PATCH 1/2 Documentation/git-checkout.txt: clarify usage

The forms of checkout that do not take a path are lumped together in the DESCRIPTION section, but the description for this group is dominated by explanation of the -b|-B form. Split these apart for more clarity.

---
 Documentation/git-checkout.txt | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
Documentation/git-checkout.txt +17 -9
index 7958a47..a47555c 100644
@@ -22,17 +22,18 @@ also update `HEAD` to set the specified branch as the current
 branch.
 
 'git checkout' [<branch>]::
+
+	Update the index, working tree, and HEAD to reflect the
+	specified branch.
+
 'git checkout' -b|-B <new_branch> [<start point>]::
-'git checkout' [--detach] [<commit>]::
 
-	This form switches branches by updating the index, working
-	tree, and HEAD to reflect the specified branch or commit.
-+
-If `-b` is given, a new branch is created as if linkgit:git-branch[1]
-were called and then checked out; in this case you can
-use the `--track` or `--no-track` options, which will be passed to
-'git branch'.  As a convenience, `--track` without `-b` implies branch
-creation; see the description of `--track` below.
+	Specifying `-b` causes a new branch to be created as if
+	linkgit:git-branch[1] were called and then checked out.  In
+	this case you can use the `--track` or `--no-track` options,
+	which will be passed to 'git branch'.  As a convenience,
+	`--track` without `-b` implies branch creation; see the
+	description of `--track` below.
 +
 If `-B` is given, <new_branch> is created if it doesn't exist; otherwise, it
 is reset. This is the transactional equivalent of
@@ -45,6 +46,13 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
+'git checkout' [--detach] [<commit>]::
+
+	Update the index and working tree to reflect the specified
+	commit and set HEAD to point directly to <commit> (see
+	"DETACHED HEAD" section.)  Passing `--detach` forces this
+	behavior even if <commit> is a branch.
+
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 
 	When <paths> or `--patch` are given, 'git checkout' does *not*
Signature · 1 line
1.8.1.rc1.203.g1ddc124
#2 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 14 lines · Chris Rorvick

The forms of checkout that do not take a path are lumped together in the DESCRIPTION section, but the description for this group is dominated by explanation of the -b|-B form. Split these apart for more clarity.

---
 Documentation/git-checkout.txt | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
Documentation/git-checkout.txt +0 -0
index 7958a47..a47555c 100644

Documentation/git-checkout.txt also update `HEAD` to set the specified branch as the current · line 27

Quoted 6 lines
Documentation/git-checkout.txt +3 -0
@@ -22,17 +22,18 @@ also update `HEAD` to set the specified branch as the current
 branch.
 
 'git checkout' [<branch>]::
+
+	Update the index, working tree, and HEAD to reflect the
+	specified branch.

This is to "check out the branch" ;-)

But of course, we cannot define "checkout" in terms of "checkout", so we need to phrase it without saying "checkout" and explain what it *means* to check out the branch.

I am not sure "Reflect" is a good word. Making the result similar to the branch is only one aspect of the act of checking out the branch. The other equally important aspect is that this is done to advance the history of the branch.

Perhaps...

Prepare to work on building new history on <branch>, by pointing the HEAD to the branch and updating the index and the files in the working tree. Local modifications to the files in the working tree are kept, so that they can be committed on the <branch>.

Quoted 12 lines
Documentation/git-checkout.txt +6 -0
 'git checkout' -b|-B <new_branch> [<start point>]::
 
+	Specifying `-b` causes a new branch to be created as if
+	linkgit:git-branch[1] were called and then checked out.  In
+	this case you can use the `--track` or `--no-track` options,
+	which will be passed to 'git branch'.  As a convenience,
+	`--track` without `-b` implies branch creation; see the
+	description of `--track` below.
 +
 If `-B` is given, <new_branch> is created if it doesn't exist; otherwise, it
 is reset. This is the transactional equivalent of

Documentation/git-checkout.txt $ git checkout <branch> · line 54

Quoted 9 lines
Documentation/git-checkout.txt +6 -0
@@ -45,6 +46,13 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
+'git checkout' [--detach] [<commit>]::
+
+	Update the index and working tree to reflect the specified
+	commit and set HEAD to point directly to <commit> (see
+	"DETACHED HEAD" section.)  Passing `--detach` forces this
+	behavior even if <commit> is a branch.

Prepare to work on building new history on top of <commit>, by detaching HEAD at the commit and ...(likewise)...

#3 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

From: "Junio C Hamano" <[email protected]> Sent: Monday, December 17, 2012 7:21 AM

Quoted 40 lines
Quoted 20 lines · Chris Rorvick

The forms of checkout that do not take a path are lumped together in the
DESCRIPTION section, but the description for this group is dominated by
explanation of the -b|-B form. Split these apart for more clarity.

---
 Documentation/git-checkout.txt | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
Documentation/git-checkout.txt +0 -0
index 7958a47..a47555c 100644
@@ -22,17 +22,18 @@ also update `HEAD` to set the specified branch as

the current
branch.

Quoted 4 lines

'git checkout' [<branch>]::
+
+ Update the index, working tree, and HEAD to reflect the
+ specified branch.

This is to "check out the branch" ;-)

But of course, we cannot define "checkout" in terms of "checkout", so we need to phrase it without saying "checkout" and explain what it *means* to check out the branch.

I am not sure "Reflect" is a good word. Making the result similar to the branch is only one aspect of the act of checking out the branch. The other equally important aspect is that this is done to advance the history of the branch.

Perhaps...

Quoted 7 lines

Prepare to work on building new history on <branch>, by pointing the HEAD to the branch and updating the index and the files in the working tree. Local modifications to the files in the working tree are kept, so that they can be committed on the <branch>.

From a user perspective it's better to refer to the working directory

first rather than the internal mechanics. Perhaps:

Prepare to work on <branch>, by updating the files in the working tree and index to the branch's previous content, and pointing HEAD to it.

Local modifications to the files in the working tree are kept, so that they can be committed on the <branch>.

Quoted 27 lines
Quoted 18 lines

'git checkout' -b|-B <new_branch> [<start point>]::

+ Specifying -b causes a new branch to be created as if
+ linkgit:git-branch[1] were called and then checked out. In
+ this case you can use the --track or --no-track options,
+ which will be passed to 'git branch'. As a convenience,
+ --track without -b implies branch creation; see the
+ description of --track below.
+
If -B is given, <new_branch> is created if it doesn't exist;
otherwise, it
is reset. This is the transactional equivalent of

Documentation/git-checkout.txt +0 -0
@@ -45,6 +46,13 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git

checkout" is
successful.

Quoted 6 lines

+'git checkout' [--detach] [<commit>]::
+
+ Update the index and working tree to reflect the specified
+ commit and set HEAD to point directly to <commit> (see
+ "DETACHED HEAD" section.) Passing --detach forces this
+ behavior even if <commit> is a branch.

Prepare to work on building new history on top of <commit>,
by detaching HEAD at the commit and ...(likewise)...

#4 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 10 lines · Philip Oakley

From: "Junio C Hamano" <[email protected]> Sent: Monday, December 17,

Quoted 2 lines

This is to "check out the branch" ;-)
...

From a user perspective it's better to refer to the working directory first rather than the internal mechanics.

Prepare to work on <branch>, by updating the files in the working tree and index to the branch's previous content, and pointing HEAD to it.

I agree that the mention of "pointing HEAD to" may be better to be rephrased in the user facing terms.

Because the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", that aspect of the behaviour should be mentioned first. Updating of the working tree files and the index is the implemenation detail of starting to work on that branch.

So your suggestion is going backwards, I'd have to say.

#5 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

From: "Junio C Hamano" <[email protected]> Sent: Monday, December 17, 2012 9:13 PM

Quoted 13 lines
Quoted 10 lines · Philip Oakley

From: "Junio C Hamano" <[email protected]> Sent: Monday, December 17,

Quoted 2 lines

This is to "check out the branch" ;-)
...

From a user perspective it's better to refer to the working directory first rather than the internal mechanics.

Prepare to work on <branch>, by updating the files in the working tree and index to the branch's previous content, and pointing HEAD to it.

Quoted 6 lines

I agree that the mention of "pointing HEAD to" may be better to be rephrased in the user facing terms.

Because the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", that aspect of the behaviour should be mentioned first.

That part is OK, but it is a bit tautological.

Quoted 3 lines

Updating of the
working tree files and the index is the implemenation detail of starting to work on that branch.

It was this part that I felt needed the worker's work-tree mentioned first.

It could be argued that workers think they do work on the tree, and that the branch name is an administrative place holder.

When the two sentences are back to back it was OK, as you had still included the key element of my suggestion.

Quoted 3 lines

So your suggestion is going backwards, I'd have to say.

A misunderstanding of the suggestion perhaps?

Philip

#6 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Philip Oakley

From: "Junio C Hamano" <[email protected]> Sent: Monday, December 17,

Quoted 2 lines

This is to "check out the branch" ;-)
...

From a user perspective it's better to refer to the working directory first rather than the internal mechanics.

Prepare to work on <branch>, by updating the files in the working tree and index to the branch's previous content, and pointing HEAD to it.

Quoted 8 lines

I agree that the mention of "pointing HEAD to" may be better to be rephrased in the user facing terms.

Because the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", that aspect of the behaviour should be mentioned first. Updating of the working tree files and the index is the implemenation detail of starting to work on that branch.

Even if the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", I don't believe that means it has to be stated first. In fact, I would say that there are enough other use cases that the language should be slightly more use-case agnostic in the first situation. For example, someone might switch to another branch or commit simply to see what state the tree was in at that point. Some people use checkout to deploy a tag of the working tree onto a production server. The first example in particular is, I think, a common enough operation that restricting the opening lines of documentation to talking about building further work is misleading.

My earlier submission dealt with this by using the 'Switch to the specified ...' terminology. For me this is implicitly stating 'Switch the state of the repository to be the same as the specified ...' but perhaps it would do to be more explicit? I prefer the shorter form myself.

By following this with the typical use case it makes it clear what the intended use of the command is, and some idea about the mechanics of its function.

I realised that my signature was improperly placed when I submitted my suggestion last, so I will include it here as reference for anyone who skipped over it. It builds on top of the two original patches.

Regards,

Andrew Ardill

-->8--

From: Andrew Ardill <[email protected]>
Date: Mon, 17 Dec 2012 18:53:41 +1100
Subject: [PATCH] Documentation/git-checkout.txt: Use consistent terminology

git checkout is described as 'switching' branches in places. Use this terminology more consistently.

Expand on the purpose of switching to a branch or commit, which is typically to prepare to build history on top of that branch or commit.

---
 Documentation/git-checkout.txt | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Documentation/git-checkout.txt +12 -6
index db89cf7..e6db14f 100644
@@ -23,8 +23,11 @@ branch.
 
 'git checkout' [<branch>]::
 
-       Update the index, working tree, and HEAD to reflect the
-       specified branch.
+       Switch to the specified <branch>. Prepares for building new
+       history on <branch>, 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 on the <branch>.
 +
 If <branch> is not found but there does exist a tracking branch in
 exactly one remote (call it <remote>) with a matching name, treat as
@@ -56,10 +59,13 @@ successful.
 
 'git checkout' [--detach] [<commit>]::
 
-       Update the index and working tree to reflect the specified
-       commit and set HEAD to point directly to <commit> (see
-       "DETACHED HEAD" section.)  Passing `--detach` forces this
-       behavior even if <commit> is a branch.
+       Switch to the specified <commit>. Prepares for building new
+       history on top of <commit>, by updating the index and the files
+       in the working tree, and by pointing HEAD at <commit>. Local
+       modifications to the files in the working tree are kept, so that
+       they can be committed on top of <commit>. Passing `--detach`
+       forces HEAD to point directly at <commit> even if <commit> is a
+       branch (see "DETACHED HEAD" section.)
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 

--

#7 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 7 lines · Andrew Ardill

Even if the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", I don't believe that means it has to be stated first. In fact, I would say that there are enough other use cases that the language should be slightly more use-case agnostic in the first situation. For example, someone might switch to another branch or commit simply to see what state the tree was in at that point.

I've been deliberately avoiding the term "switch", actually. I agree that it may be familiar to people with prior exposure to subversion, but that is not the primary audience of the manual.

Quoted 5 lines

Some people use checkout to
deploy a tag of the working tree onto a production server. The first example in particular is, I think, a common enough operation that restricting the opening lines of documentation to talking about building further work is misleading.

I agree with you that sightseeing use case where you do not intend to make any commit is also important. That is exactly why I said "further work is done on that branch" not "to that branch" in the message you are responding to.

#13 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Junio C Hamano

Am 12/17/2012 8:21, schrieb Junio C Hamano:

Quoted 2 lines
Quoted 1 line · Chris Rorvick

'git checkout' [<branch>]::

Is <branch> really optional in this form?

BTW, what does plain 'git checkout' do? Just report ahead/behind information?

Quoted 3 lines
Quoted 3 lines
Documentation/git-checkout.txt +3 -0
+
+	Update the index, working tree, and HEAD to reflect the
+	specified branch.

...

Quoted 1 line
Quoted 1 line

+'git checkout' [--detach] [<commit>]::

The title here is better spelled as two lines:

'git checkout' <commit>::
'git checkout' --detach <branch>::

I don't think that <commit> or <branch> should be indicated as optional here.

Quoted 8 lines

Documentation/git-checkout.txt $ git checkout <branch> · line 54

Quoted 5 lines
Documentation/git-checkout.txt +5 -0
+
+	Update the index and working tree to reflect the specified
+	commit and set HEAD to point directly to <commit> (see
+	"DETACHED HEAD" section.)  Passing `--detach` forces this
+	behavior even if <commit> is a branch.

Prepare to work on building new history on top of <commit>, by detaching HEAD at the commit and ...(likewise)...

-- Hannes

#14 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Here is what I tentatively have (so that I do not forget) on 'pu', marked with "(squash???)", as a suggested update on top of Chris's patches.

 Documentation/git-checkout.txt | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
Documentation/git-checkout.txt +21 -8
index db89cf7..0e50eeb 100644
@@ -21,10 +21,13 @@ or the specified tree.  If no paths are given, 'git checkout' will
 also update `HEAD` to set the specified branch as the current
 branch.
 
-'git checkout' [<branch>]::
+'git checkout' <branch>::
 
-	Update the index, working tree, and HEAD to reflect the
-	specified branch.
+	Prepare to work on building new history on <branch>, by
+	pointing the HEAD to the branch and updating the index and
+	the files in the working tree.  Local modifications to the
+	files in the working tree are kept, so that they can be
+	committed on the <branch>.
 +
 If <branch> is not found but there does exist a tracking branch in
 exactly one remote (call it <remote>) with a matching name, treat as
@@ -33,6 +36,11 @@ equivalent to
 ------------
 $ 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 a
+rather expensive side-effects to show only the tracking information,
+if exists, for the current branch.
 
 'git checkout' -b|-B <new_branch> [<start point>]::
 
@@ -54,12 +62,17 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' [--detach] [<commit>]::
+'git checkout' --detach [<commit>]::
+'git checkout' <commit>::
 
-	Update the index and working tree to reflect the specified
-	commit and set HEAD to point directly to <commit> (see
-	"DETACHED HEAD" section.)  Passing `--detach` forces this
-	behavior even if <commit> is a branch.
+	Prepare to work on building new history on top of <commit>,
+	by detaching HEAD at the commit (see "DETACHED HEAD"
+	section), and updating the index and the files in the
+	working tree.  Local modifications to the files in the
+	working tree are kept, so that they can be committed on the
+	<branch>.
++
+Passing `--detach` forces this behavior even if <commit> is a branch.
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 
#15 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Am 12/17/2012 9:48, schrieb Junio C Hamano:

Quoted 1 line

Here is what I tentatively have ...

Thanks!

Quoted 4 lines

-'git checkout' [--detach] [<commit>]::
+'git checkout' --detach [<commit>]::
+'git checkout' <commit>::

Documentation/git-checkout.txt $ git checkout <branch> · line 73

Quoted 10 lines
Documentation/git-checkout.txt +6 -4
-	Update the index and working tree to reflect the specified
-	commit and set HEAD to point directly to <commit> (see
-	"DETACHED HEAD" section.)  Passing `--detach` forces this
-	behavior even if <commit> is a branch.
+	Prepare to work on building new history on top of <commit>,
+	by detaching HEAD at the commit (see "DETACHED HEAD"
+	section), and updating the index and the files in the
+	working tree.  Local modifications to the files in the
+	working tree are kept, so that they can be committed on the
+	<branch>.

The last half-sentence should better be removed.

Quoted 4 lines

++
+Passing --detach forces this behavior even if <commit> is a branch.

'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::

-- Hannes

#16 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 9 lines · Johannes Sixt

Am 12/17/2012 9:48, schrieb Junio C Hamano:

Quoted 1 line

Here is what I tentatively have ...

Thanks!

Quoted 4 lines

-'git checkout' [--detach] [<commit>]::
+'git checkout' --detach [<commit>]::
+'git checkout' <commit>::

Quoted 12 lines

Documentation/git-checkout.txt $ git checkout <branch> · line 73

Quoted 10 lines
Documentation/git-checkout.txt +6 -4
-	Update the index and working tree to reflect the specified
-	commit and set HEAD to point directly to <commit> (see
-	"DETACHED HEAD" section.)  Passing `--detach` forces this
-	behavior even if <commit> is a branch.
+	Prepare to work on building new history on top of <commit>,
+	by detaching HEAD at the commit (see "DETACHED HEAD"
+	section), and updating the index and the files in the
+	working tree.  Local modifications to the files in the
+	working tree are kept, so that they can be committed on the
+	<branch>.

The last half-sentence should better be removed.

True; we do not have a particular "on the <branch>" in this state. At least, "on the <branch>" needs to be removed. But I think we may want a more different wording here, including the earlier "work on building new history on top of" part.

The detached HEAD state primarily is a sightseeing mode, where the user is expected to view but not touch. Even for experienced users, commits on a detached HEAD are for keeping snapshots of interim states during a throw-away experiment, so the purpose of detaching is not exactly "to work on *building* new history" in the first place.

Carefree experimentation is encouraged by not forbidding commmits from this state, with the expectation that:

(1) if it does not lead to interesting result, another "git checkout <branch>" will wipe the throw-away experiment without affecting any of your more important branches; and

(2) an experiment that yielded something useful can be further polished on a concrete branch by "git checkout -b <newbranch>".

I think the above discussion on detached HEAD can be added to its own section.

Prepare to work on top of <commit>, by detaching HEAD at it (see "DETACHED HEAD" section), and updating te index and the files in the working tree. Local modifications to the files in the working tree are kept, so that the resulting working tree will be the state recorded in the commit plus the local modifications.

Or something, perhaps?

#17 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Johannes Sixt

Regards,

Andrew Ardill

Quoted 7 lines · Johannes Sixt

Am 12/17/2012 8:21, schrieb Junio C Hamano:

Quoted 2 lines
Quoted 1 line · Chris Rorvick

'git checkout' [<branch>]::

Is <branch> really optional in this form?

BTW, what does plain 'git checkout' do? Just report ahead/behind information?

I think it defaults to either HEAD or the current branch, which shows uncommitted changes and relationship to upstream.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3 -0
+
+    Update the index, working tree, and HEAD to reflect the
+    specified branch.

...

Quoted 8 lines
Quoted 1 line
Quoted 1 line

+'git checkout' [--detach] [<commit>]::

The title here is better spelled as two lines:

'git checkout' <commit>::
'git checkout' --detach <branch>::

I don't think that <commit> or <branch> should be indicated as optional here.

doing 'git checkout --detach' will detach from the current branch if you have one, but maybe listing <branch> as optional would work in that case?

Here is my suggestion, differing from what Junio put forward primarily by first indicating that a checkout is a 'switch' to a different branch or commit. This makes sense to me, and is used elsewhere in the documentation, so I thought it might make sense here too.

-->8--

From: Andrew Ardill <[email protected]>
Date: Mon, 17 Dec 2012 18:53:41 +1100
Subject: [PATCH] Documentation/git-checkout.txt: Use consistent terminology

git checkout is described as 'switching' branches in places. Use this terminology more consistently.

Expand on the purpose of switching to a branch or commit, which is typically to prepare to build history on top of that branch or commit.

---
 Documentation/git-checkout.txt | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Documentation/git-checkout.txt +12 -6
index db89cf7..e6db14f 100644
@@ -23,8 +23,11 @@ branch.
 
 'git checkout' [<branch>]::
 
-       Update the index, working tree, and HEAD to reflect the
-       specified branch.
+       Switch to the specified <branch>. Prepares for building new
+       history on <branch>, 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 on the <branch>.
 +
 If <branch> is not found but there does exist a tracking branch in
 exactly one remote (call it <remote>) with a matching name, treat as
@@ -56,10 +59,13 @@ successful.
 
 'git checkout' [--detach] [<commit>]::
 
-       Update the index and working tree to reflect the specified
-       commit and set HEAD to point directly to <commit> (see
-       "DETACHED HEAD" section.)  Passing `--detach` forces this
-       behavior even if <commit> is a branch.
+       Switch to the specified <commit>. Prepares for building new
+       history on top of <commit>, by updating the index and the files
+       in the working tree, and by pointing HEAD at <commit>. Local
+       modifications to the files in the working tree are kept, so that
+       they can be committed on top of <commit>. Passing `--detach`
+       forces HEAD to point directly at <commit> even if <commit> is a
+       branch (see "DETACHED HEAD" section.)
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 

--

#19 lore raw

PATCH 2/2 Documentation/git-checkout.txt: document 70c9ac2 behavior

In reply to Chris Rorvick

Document the behavior implemented in 70c9ac2 (DWIM "git checkout frotz" to "git checkout -b frotz origin/frotz").

---
 Documentation/git-checkout.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/git-checkout.txt +8 -0
index a47555c..db89cf7 100644
@@ -25,6 +25,14 @@ branch.
 
 	Update the index, working tree, and HEAD to reflect the
 	specified branch.
++
+If <branch> is not found but there does exist a tracking branch in
+exactly one remote (call it <remote>) with a matching name, treat as
+equivalent to
++
+------------
+$ git checkout -b <branch> --track <remote>/<branch>
+------------
 
 'git checkout' -b|-B <new_branch> [<start point>]::
 
Signature · 1 line
1.8.1.rc1.203.g1ddc124
#20 lore raw

Re: [PATCH 2/2] Documentation/git-checkout.txt: document 70c9ac2 behavior

Quoted 16 lines · Chris Rorvick

Document the behavior implemented in 70c9ac2 (DWIM "git checkout frotz" to "git checkout -b frotz origin/frotz").

---
 Documentation/git-checkout.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/git-checkout.txt +0 -0
index a47555c..db89cf7 100644
@@ -25,6 +25,14 @@ branch.
 
 	Update the index, working tree, and HEAD to reflect the
 	specified branch.

Documentation/git-checkout.txt branch. · line 37

Quoted 10 lines
Documentation/git-checkout.txt +8 -0
++
+If <branch> is not found but there does exist a tracking branch in
+exactly one remote (call it <remote>) with a matching name, treat as
+equivalent to
++
+------------
+$ git checkout -b <branch> --track <remote>/<branch>
+------------
 
 'git checkout' -b|-B <new_branch> [<start point>]::

Thanks; does it format well (I didn't check)?

#21 lore raw

Re: [PATCH 2/2] Documentation/git-checkout.txt: document 70c9ac2 behavior

Quoted 1 line · Junio C Hamano

does it format well (I didn't check)?

It applied cleanly for me on latest master, and the output looked consistent with existing documentation.

Regards,

Andrew Ardill

#22 lore raw

Re: [PATCH 2/2] Documentation/git-checkout.txt: document 70c9ac2 behavior

Quoted 5 lines · Andrew Ardill
Quoted 1 line · Junio C Hamano

does it format well (I didn't check)?

It applied cleanly for me on latest master, and the output looked consistent with existing documentation.

Thanks.

#8 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

I agree with you that sightseeing use case where you do not intend to make any commit is also important. That is exactly why I said "further work is done on that branch" not "to that branch" in the message you are responding to.

Here is a work-in-progress relative to Chris's 83c9989 (Documentation/git-checkout.txt: document 70c9ac2 behavior, 2012-12-17).

Even though "switch to that specific branch" may be easy to grasp as a concept, I do not think "switch to detached HEAD" makes much sense, so I ended up with "switch" for the <branch> case, and "detach" for the "--detach" one, at least for now.

Documentation/git-checkout.txt +21 -9
index db89cf7..dcf1a32 100644
@@ -21,10 +21,12 @@ or the specified tree.  If no paths are given, 'git checkout' will
 also update `HEAD` to set the specified branch as the current
 branch.
 
-'git checkout' [<branch>]::
-
-	Update the index, working tree, and HEAD to reflect the
-	specified branch.
+'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>.
 +
 If <branch> is not found but there does exist a tracking branch in
 exactly one remote (call it <remote>) with a matching name, treat as
@@ -33,6 +35,11 @@ equivalent to
 ------------
 $ 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 a
+rather expensive side-effects to show only the tracking information,
+if exists, for the current branch.
 
 'git checkout' -b|-B <new_branch> [<start point>]::
 
@@ -54,12 +61,17 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' [--detach] [<commit>]::
+'git checkout' --detach [<commit>]::
+'git checkout' <commit>::
 
-	Update the index and working tree to reflect the specified
-	commit and set HEAD to point directly to <commit> (see
-	"DETACHED HEAD" section.)  Passing `--detach` forces this
-	behavior even if <commit> is a branch.
+	Prepare to work on top of <commit>, by detaching HEAD at it
+	(see "DETACHED HEAD" section), and updating the index and the
+	files in the working tree.  Local modifications to the files
+	in the working tree are kept, so that the resulting working
+	tree will be the state recorded in the commit plus the local
+	modifications.
++
+Passing `--detach` forces this behavior even if <commit> is a branch.
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 
#9 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 3 lines · Junio C Hamano

Here is a work-in-progress relative to Chris's 83c9989 (Documentation/git-checkout.txt: document 70c9ac2 behavior, 2012-12-17).

It sounds pretty good to me.

Quoted 13 lines
(quoted diff) +3 -5
@@ -54,12 +61,17 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' [--detach] [<commit>]::
+'git checkout' --detach [<commit>]::
+'git checkout' <commit>::
 
-       Update the index and working tree to reflect the specified
-       commit and set HEAD to point directly to <commit> (see
-       "DETACHED HEAD" section.)  Passing `--detach` forces this
-       behavior even if <commit> is a branch.
+       Prepare to work on top of <commit>, by detaching HEAD at it

Review $ git checkout <branch> · line 77

Quoted 10 lines
(quoted diff) +7 -0
+       (see "DETACHED HEAD" section), and updating the index and the
+       files in the working tree.  Local modifications to the files
+       in the working tree are kept, so that the resulting working
+       tree will be the state recorded in the commit plus the local
+       modifications.
++
+Passing `--detach` forces this behavior even if <commit> is a branch.
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 

I like Johannes' suggestion of using "<branch>" in the --detach case instead of "<commit>" as I think it makes the reason for the separation more obvious at a glance. On top of your changes, maybe something like:

--->8---

Documentation/git-checkout.txt +3 -2
index dcf1a32..4fdf41a 100644
@@ -61,8 +61,8 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' --detach [<commit>]::
 'git checkout' <commit>::
+'git checkout' --detach [<branch>]::
 
        Prepare to work on top of <commit>, by detaching HEAD at it
        (see "DETACHED HEAD" section), and updating the index and the
@@ -71,7 +71,8 @@ successful.
        tree will be the state recorded in the commit plus the local
        modifications.
 +
-Passing `--detach` forces this behavior even if <commit> is a branch.
+Passing `--detach` forces this behavior in the case of a <branch>, or
+the current branch if one is not specified.
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
#10 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

Quoted 3 lines · Chris Rorvick

I like Johannes' suggestion of using "<branch>" in the --detach case instead of "<commit>" as I think it makes the reason for the separation more obvious at a glance.

Sounds sensible; even though the option does not require its argument to be a branch name, the user does not have a reason to use the option if it is not giving a branch name, either, so it all balances out ;-).

Quoted 25 lines

--->8---

Documentation/git-checkout.txt +3 -2
index dcf1a32..4fdf41a 100644
@@ -61,8 +61,8 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' --detach [<commit>]::
 'git checkout' <commit>::
+'git checkout' --detach [<branch>]::
 
        Prepare to work on top of <commit>, by detaching HEAD at it
        (see "DETACHED HEAD" section), and updating the index and the
@@ -71,7 +71,8 @@ successful.
        tree will be the state recorded in the commit plus the local
        modifications.
 +
-Passing `--detach` forces this behavior even if <commit> is a branch.
+Passing `--detach` forces this behavior in the case of a <branch>, or
+the current branch if one is not specified.
 
 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
#11 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Junio C Hamano

I like these, and I think they are conveying the right amount of information. There is a slight discrepancy between the <branch> and <commit> versions, where it seems we are assuming that by checking out a commit you are intending to work 'on top of' it. This could be avoided by using the term 'with' in both cases. Also, they are in different tenses, but I'm not sure which is preferred ('Prepare to' vs 'To prepare for').

In the second tense, these opening lines might look like this:

+ To prepare for working with <branch>, switch to it by updating

+       To prepare for working with <commit>, detach HEAD at it
+       (see "DETACHED HEAD" section), and update the index and the
+       files in the working tree.

Regards,

Andrew Ardill

#12 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Andrew Ardill

Even if the primary purpose of "git checkout <branch>" is to "check out the branch so that further work is done on that branch", I don't believe that means it has to be stated first. In fact, I would say that there are enough other use cases that the language should be slightly more use-case agnostic in the first situation. For example, someone might switch to another branch or commit simply to see what state the tree was in at that point.

Quoted 3 lines

I've been deliberately avoiding the term "switch", actually. I agree that it may be familiar to people with prior exposure to subversion, but that is not the primary audience of the manual.

I don't have much experience with svn, so I didn't make that connection. Independent of svn usage, what is wrong with the term 'switch'?

I would be interested to hear how translators communicate the checkout concept, as I assume the word checkout doesn't exist in many languages. For me, switching between revisions is a natural way of phrasing the action, but perhaps there is a better way of saying the same thing?

Quoted 10 lines
Quoted 5 lines

Some people use checkout to
deploy a tag of the working tree onto a production server. The first example in particular is, I think, a common enough operation that restricting the opening lines of documentation to talking about building further work is misleading.

I agree with you that sightseeing use case where you do not intend to make any commit is also important. That is exactly why I said "further work is done on that branch" not "to that branch" in the message you are responding to.

Ah ok, I didn't pick up on that nuance. Your suggestion from earlier has, for example, "Prepare to work on building new history on <branch>" which *is* excluding that use case. Perhaps modifying similar lines to something like "Prepare to work with the repository/history/something from <branch>" or maybe just "Prepare to work with <branch>" would better encapsulate those use cases. Following lines would expand on what it means to work with a branch or commit, and the technical details of updates to the repositories current state.

Regards,

Andrew Ardill

#18 lore raw

Re: [PATCH 1/2] Documentation/git-checkout.txt: clarify usage

In reply to Johannes Sixt
Quoted 6 lines · Johannes Sixt
Quoted 1 line
Quoted 1 line

+'git checkout' [--detach] [<commit>]::

The title here is better spelled as two lines:

'git checkout' <commit>::
'git checkout' --detach <branch>::

AsciiDoc renders these horizontally separated by a comma when formatted as a man page instead of vertically as written (and as rendered by the HTML documentation.) I think this makes this separation into two less effective, but at least it doesn't line wrap on an 80-wide terminal like the previous title did.

Chris