1

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 test.txt 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 test.txt file in my local repository.

At this point, I'd like to copy the test.txt file from the remote repository into the local repository. If I delete my local repository and clone the remote repository, the test.txt file shows up just fine. But, I'm not sure how to recreate the test.txt 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 test.txt 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.

Update: 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 means.

  • If you're a newbie to Git, I recommend *avoiding* `git pull`. The pull command is meant as a convenience: it runs `git fetch` first, then another Git command, usually `git merge`. The thing is that the *way* it runs the second command: (1) obscures how Git is working and makes it harder to learn; (2) leaves you with nowhere to turn if the second command blows up, as it eventually does. If you run the second command yourself, you get to see what's happening and hence a handle on how to fix it. (Item 3, "pull" was full of bugs, was mostly fixed by Git 2.0...) – torek Nov 22 '16 at 22:40

1 Answers1

0

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

Community
  • 1
  • 1
dubes
  • 5,324
  • 3
  • 34
  • 47
  • `git reset --hard HEAD` did it. Thanks. I'm not clear on the difference between saying `HEAD` and `origin/master`. –  Nov 22 '16 at 20:13
  • glad to have helped, git takes a while to wrap your head around, but is awesome... take a look at this answer to understand what head is: http://stackoverflow.com/questions/2529971/what-is-the-head-in-git and also look at the man pages for git pull and git reset – dubes Nov 22 '16 at 20:18