Checkout the branch with -B
: this will reset the branch to HEAD, which is the current ref.
git checkout -B <branch>
From the docs:
If -B is given, is created if it doesn’t exist;
otherwise, it is reset. This is the transactional equivalent of$ git branch -f <branch> [<start point>] $ git checkout <branch>
that is to say, the branch is not reset/created unless “git
checkout” is successful.