jkulak jkulak - 7 months ago 47
Git Question

Why would I ever git checkout --detach

I understand what's happening under the hood, when I run

$ git checkout --detach

While on
, when I
$ git checkout --detach
, my
is not pointing to
ref: refs/heads/master
but to a hash instead (same a as

What would be the use case, when I would actually want to do that?


According to the commit that introduced the flag:

For example, one might use this when making a temporary merge to test that two topics work well together.

I guess the idea is that deliberately detaching allows you to then make further commits that you know will be discarded once you're done (and once GC has run).

Note that this flag doesn't actually add any new functionality; you could achieve the same result previously with git checkout some-branch^0.