jkulak jkulak - 19 days ago 5
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
master
, when I
$ git checkout --detach
, my
.git/HEAD
is not pointing to
ref: refs/heads/master
but to a hash instead (same a as
refs/heads/master
).

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

Answer

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.