Reimplementing Repository::getBranch according to gitelephant.patch