BarrettNashville BarrettNashville - 1 year ago 68
Git Question

Why is git "pull origin master" not re-creating all the remote files in the local repo?

I'm a git novice, but I've been able to create a bare remote repository on a shared drive so it can be shared with co-workers. I created a

file, added it to the local repository, committed it to the local repository, and then pushed it into the remote repository. Then I delete the
file in my local repository.

At this point, I'd like to copy the
file from the remote repository into the local repository. If I delete my local repository and clone the remote repository, the
file shows up just fine. But, I'm not sure how to recreate the
file in the local repository without completely deleting the repository and starting over.

Based upon what I've read, I think I should be able to run
git pull origin master
, but when I do that, the
file does not reappear in my local repository.

I'm still wrapping my head around git, so I may be thinking about this incorrectly. I guess I'm thinking that I should be able to just "reset" the local repo to the remote repo and start over without cloning it again.

I just tried this and it seemed to work:
git reset --hard origin/master
. Not sure if that's the right way to do it or exactly what
--hard origin/master

Answer Source

When you delete a "committed" file locally, git on your machine tracks it as a change. So, git pull will not overwrite your local changes unless you ask it to.

You can try by running the command git status after you have deleted, before you pull and after you pull.

If you want to reset your local repository with remote repository, the command you are looking for is git reset --hard HEAD

I would also recommend this awesome thread to help you get started with git

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download