Back

Explore Courses Blog Tutorials Interview Questions
+9 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

How do I reset my local branch to be just like the branch on the 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 <file>..." to
unstage)
      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? If I did, I want to remove those.

1 Answer

+11 votes
by (27.5k points)
edited by

Before I mention the steps, here's a tip if you want to save your current branch's state:

git commit -a -m "Saving my work in my-saved-work branch"
git branch my-saved-work

Now let us set our branch to exactly match the remote branch:

git fetch origin
git reset --hard origin/master

Here, the remote repository named "origin" and that the branch named "master" in the remote repository matches the currently checked-out branch in your local repository.

Now addressing your next query, to remove those untracked files, use the following commands. But before performing clean take a look at the files that will be cleaned.

git clean -n -f

Now if you think these files add no value and can be removed, use the following command:

git clean -f

For more information please go through the following tutorial to get more info about git:

 

by (19.4k points)
This was helpful

Browse Categories

...