Reset Local Repository Branch to Be Just like Remote Repository Head

Better Stack Team
Updated on June 24, 2024

To reset your local repository branch to be just like the remote repository's HEAD (i.e., the latest state of the branch in the remote repository), you can use the git reset command along with the remote branch reference. Here's how you can do it:

 
git fetch origin     # Fetch the latest changes from the remote repository
git reset --hard origin/<branch-name>

Replace <branch-name> with the name of the branch you want to reset to match the remote repository's HEAD.

  • git fetch origin: This command fetches the latest changes from the remote repository but doesn't merge them into your local branch yet.
  • git reset --hard origin/<branch-name>: This command resets your local branch to match the state of the specified branch in the remote repository (origin/<branch-name>) and discards any local changes.

By using these commands, you'll reset your local repository branch to match the latest state of the branch in the remote repository. Make sure to use caution with git reset --hard as it will discard any local changes that are not present in the remote branch.