0

I want get complete latest code from the git server and need to override my local machine changes. Meaning I want to remove all my local untrack files and directories and than get the latest code from the remote repository. Is it possible to do with git?

Vijendran Selvarajah
  • 1,330
  • 1
  • 11
  • 31
pravin p
  • 75
  • 6
  • 3
    Possible duplicate of [How do I force "git pull" to overwrite local files?](https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files) – georgexsh Nov 24 '17 at 12:49

2 Answers2

4

As per your question, I have understood, you have to remove all you untrack files (files which you have changed in your local machine) and get latest code from the remote repository and keep your git tree clean. if my understanding is correct, please find the solution for this question below:

Please note when you do this, you will loose all your uncommitted local changes.

Step 1 To remove the untrack files

git checkout .
git clean -f

Step 2 To remove the untrack directories

git clean -f -d

Step 3 To get latest codes

git fetch --all
git reset --hard <remote>/<branch_name>

For example

git checkout .
git clean -f
git clean -f -d
git fetch --all
git reset --hard origin/master
Vijendran Selvarajah
  • 1,330
  • 1
  • 11
  • 31
0

Try this:

git reset --hard HEAD
git pull

You'll lose anything that's not in the repo though

iBug
  • 35,554
  • 7
  • 89
  • 134
Alex Nevado
  • 23
  • 1
  • 3