Skip to main content
3 of 3
Fix missing placeholders hidden by HTML interpretation of angle brackets in last command. Normalized code sections.

If you want to move a non-checked out branch to another commit, the easiest way is running the git branch command with -f option, which determines where the branch HEAD should be pointing to:

git branch -f <branch-name> (<sha1-commit-hash> or <branch-name>)

For example if you want your local develop branch to track the remote (origin) develop branch:

git branch -f develop origin/develop

Be careful as this won't work if the branch you are trying to move is your current branch. To move a branch pointer, run the following command:

git update-ref -m "reset: Reset <branch-name> to <sha1-commit-hash>" \
  refs/heads/<branch-name> <sha1-commit-hash>`

The git update-ref command updates the object name stored in a ref safely.

Hope, my answer helped you.The source of information is this snippet.