checking out a detached HEAD breaks Repo.head.reference · Issue #2230 · gitpython-developers/GitPython
Repository navigation
checking out a detached HEAD breaks Repo.head.reference #2230
New issue
New issue
Closed as not planned
Closed as not planned
checking out a detached HEAD breaks Repo.head.reference #2230
Description
@tiltingpenguin's profile tiltingpenguin opened on Sep 9, 2026While building this package for openSUSE and running the testsuite we encountered a lot of test failures like this
self = <git.HEAD "HEAD">
def _get_reference(self) -> "Reference":
"""
:return:
:class:`~git.refs.reference.Reference` object we point to
:raise TypeError:
If this symbolic reference is detached, hence it doesn't point to a
reference, but to a commit.
"""
sha, target_ref_path = self._get_ref_info(self.repo, self.path)
if target_ref_path is None:
> raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
E TypeError: HEAD is a detached symbolic reference as it points to '3481da9618e69063464c94447167d83bd45505a9'
git/refs/symbolic.py:446: TypeError
It seems that this only occurs when checking out a revision instead of a branch, aka when the ref in .git/HEAD points to a commit instead of something like ref: refs/heads/master.
Repo.head.reference in git/repo/base.py fails to resolve references to commit hashes which I would expect to work.
Also there is an unrelated problem where TestRemote.test_base hardcodes the branch name as "master" which leads to the test failing when checking out any other branch.