11

I accidentally deleted some files from my source directories. I need to just re-fetch the entire git repository (git pull doesn't work because these files haven't changed since my last commit). My repository is up to date. How do I just get the entire repository? It's OK if it overwrites what's there

Jeff Hornby
  • 12,948
  • 4
  • 40
  • 61

2 Answers2

9

Your repo's files are already inside the .git directory stored as git objects. You just need to switch your working copy's state to an untouched one.

Run the following command from the root of your repo to unstage any changes you have in the git's staging area:

git reset HEAD .

Then run the following command, to discard all changes in the currently checked out branch:

git checkout -- .

git pull is required only if you need to fetch updated changes from the remote repository into your local one and merge the remote changes for the current branch into the local one. Based on what I understood from your question at least, git pull is not required.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
2

There are two simple way to reset your checkout:

git checkout .

This will reset your checkout to the state of your current branch.

git reset --hard origin/master

This will reset your checkout to the state of your remote tracking branch (assumed to be master). This is useful if you've made some commits locally, which you don't care to keep.

AD7six
  • 63,116
  • 12
  • 91
  • 123