Fix branch switching for non-shallow checkouts