annedroiid annedroiid - 1 year ago 118
Git Question

How to go back to latest remote commit git

I had to go back to an earlier commit of my code locally, so I used

git reset --hard <tag>
to go back to that commit, how do I now go back to what the latest commit was (according to the remote repository)?

Answer Source

Assuming that you have not done a fetch since your last sync with the remote tracking branch, then you should be able to reset your branch to what the latest commit was in the remote at the time you last synched:

git reset --hard origin/yourBranch

If you want to sync your branch with what the latest remote is, you can just try pulling:

git pull origin yourBranch

But make sure you commit all your work first, and expect that there might be merge conflicts.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download