Git Reset To Remote: Reset Local Repository Branch To Be Just Like Remote Repository HEAD

354    Asked by Aashishchaursiya in Devops , Asked on Nov 23, 2022

How to reset local branch to remote repository?

I did:
git reset --hard HEAD
But when I run a git status,
On branch master
Changes to be committed:
  (use "git reset HEAD ..." tounstage)

   modified:   java/com/mycompany/TestContacts.java

   modified:   java/com/mycompany/TestParser.java

Can you please tell me why I have these 'modified'? I haven't touched these files? How to remove these modifications.

For git reset branch to remote -

First, use git reset to reset to the previously fetched HEAD of the corresponding upstream branch:
git reset --hard @{u}
The advantage of specifying @{u} or its verbose form @{upstream} is that the name of the remote repo and branch don't have to be explicitly specified. On Windows or with PowerShell, specify "@{u}" (with double quotes).
Next, as needed, use git clean to remove untracked files, optionally also with -x:
git clean -df
Finally, as needed, get the latest changes:
git pull

Your Answer

Interviews

Parent Categories