Manishearth Manishearth - 3 months ago 19
Git Question

Checkout the commit corresponding to a branch

I'm using

git worktree
, and want to check out a branch which is also checked out on a different workdir. I don't need the branch itself, but I need the commit corresponding to the branch as a detached HEAD.
git checkout $(git rev-parse mybranch)
is one solution, but it's verbose (and I'd prefer to not add an alias for it if a simple way exists already). Is there any way to succinctly check out the commit corresponding to a branch?

Answer

As per git help checkout, the direct and un-magical solution is:

git checkout --detach mybranch
Comments