Git : Reset a Branch to the last thing in the remote repository

There are sometimes were we have a remote brach in our local that we haven’t been used for a while, and a given day we need to work on that branch and when we try to pull the content from the remote we get a lot of conflicts to pull the files.

An easy way to get the latest files discarding all the things that we have in the local is to fetch all the remote content and then reset the branch to the last thing in the remote. The commands for that are

[cc lang=”php” width=”100%”]

git fetch origin
git checkout mybranch
git reset –hard origin/mybranch


The trick is the fetch at the beginning, that pulls all the latest data from the remote and will not try to merge into the brach. When we do the git reset –hard from origin/mybranch will use this remote data pulled previously to merge into our local branch.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.