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

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>)

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

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 to " refs/heads/

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.

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 to " refs/heads/

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.

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.

Clarify with an example
Source Link
Mansoor
  • 2.4k
  • 1
  • 18
  • 29

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:

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

For example if you want your local develop branch to track the remote -f (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 to " refs/heads/

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.

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

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 to " refs/heads/

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.

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 to " refs/heads/

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.

Source Link

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

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 to " refs/heads/

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.