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
The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.
When downloading materials to your laptop, it is easiest to download the entire repository. To do this, go to the GitHub page for the workshop, click on the green Code button, then download the repository as a ZIP file. The filename may be different than what's in the picture. Find the downloaded .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With