Mot Mot - 1 month ago 20
Git Question

Git: move branch pointer to different commit without checkout

To move the branch pointer of a checked out branch, one can use the

git reset --hard
command. But how to move the branch pointer of a not-checked out branch to point at a different commit (keeping all other stuff like tracked remote branch)?

Answer

N.B. If you simply want to move a branch to another commit, this method is probably not the easiest option. branch -f as detailed by Chris Johnsen is a simpler command, so see his answer.

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>

The general form:

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.