Add support for detached heads, preventing fatal error.