checkout: Teach checkout to cope with orphaned Head

Fix #1236
Fix Travis compilation warnings
Merge pull request #1238 from nulltoken/fix/checkout-index

checkout: Teach checkout to cope with orphaned Head