Re: [1.8.0] git checkout refs/heads/foo checks out branch foo
From: Jeff King <hidden>
Date: 2016-06-15 22:50:31
On Mon, Feb 07, 2011 at 06:01:51AM -0500, Martin von Zweigbergk wrote:
'git checkout refs/heads/foo' (or 'git checkout heads/foo' for that matter) does not check out the branch, but instead detaches HEAD at foo. This is quite counter-intuitive (at least to me) and the same functionality can be achieved by using e.g. foo~0. Change the behavior so that the branch is actually checked out. This also applies to e.g. 'git rebase master refs/heads/topic', which currently rebases a detached HEAD. There are probably other examples as well that I'm not aware of.
I have seen that behavior claimed as intentional, but I agree it is unintuitive. In most other places referring to a ref by a short name or a fully qualified name is equivalent (except with respect to disambiguating short names, of course).
Existing scripts may depend on the current behavior. It seems unlikely that many users depend on it. Most likely, they use foo~0 or foo^0 instead.
As cool and clever as the foo^0 behavior is once you understand it, I think it is a horribly confusing thing for non-experts. As part of this proposal, should we perhaps offer "git checkout --detach" as the easy-on-the-eyes way of intentionally detaching? -Peff