Move branch pointer to different commit without checkout
git branch --force <branch-name> [<new-tip-commit>]
If new-tip-commit
is omitted, it defaults to the current commit.
new-tip-commit
can be a branch name (e.g., master, origin/master).
You can do it for arbitrary refs. This is how to move a branch pointer:
git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>
where -m
adds a message to the reflog for the branch.
The general form is
git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>
You can pick nits about the reflog message if you like - I believe the branch -f
one is different from the reset --hard
one, and this isn't exactly either of them.