checkout: Teach checkout to cope with orphaned Head

Fix #1236