Is it possible to end in git detached head from pull, push, fetch or rebase?

144 views Asked by At

I have a python server application that handles a git repository. It creates commits and switches branches to apply changes locally and then pushes them to the remote repo.

For some reason, users that run the server on Mac see their repository ending up in a detached HEAD state. This has never happen for users running the server on Windows machines.

The tool uses GitPython, and there is no service that does a checkout to a specific commit SHA, it only switches to branch names. It does perform git pull --rebase and git push.

Is there a way to end up in the detached HEAD state by performing pulls with rebase, fetches or pushes, or any other way that is not a checkout to a commit SHA?

2

There are 2 answers

7
torek On

An incomplete rebase—one that stops due to a merge conflict, typically, though any kind of error, such as a permissions problem, will also do it—will leave you in the middle of the rebase. Rebase itself uses detached-HEAD mode, so you will have a detached HEAD here. That's the most likely source of the problem.

(As eftshift0 noted in a comment, passing a tag name to git checkout, or any name that's not a branch name, also results in a detached HEAD.)

0
Haibrayn González On

Looks like the error was caused by git-lfs not installed by default in the macOS from the work machines. The plug-in failed somehow and ended in detached HEAD state