Fix #310 detach HEAD problem when updating