1

I've tried pretty much all of these, none appear to work: How do I force "git pull" to overwrite local files?

Here's 2 scenarios:

A) Delete a local file

1) git clone my_repo
2) cd my_repo
3) delete some file
4) git pull
  > Already up to date

No it isn't I have deleted some files, why is it not pulling down the missing files ??

B) Change a File

1) git clone my_repo
2) cd my_repo
3) echo "xxx" >> some file
4) git pull
  > Already up to date

It is not up to date, I have changed a file !

How can I force git to re-sync with the remote master ?

EDIT

I should have mentioned initially that this is for deployment, hence the requirement to effectively sync the local with the master.

2
  • The purpose of pull is to be a convenient shortcut for git fetch followed by git merge (or you can make it do git rebase instead of git merge). Note that git merge is not intended to make your code exactly match some other code: that would be silly; you would lose all the stuff you worked on yourself.
    – torek
    Commented Apr 18, 2014 at 11:52
  • This does not answer your question, but: Please not that git is not a deployment tool. Consider using a tool specifically suited for deployments.
    – sleske
    Commented Apr 18, 2014 at 13:06

2 Answers 2

2

The pull command syncs your local repo with the remote repo. If you already have the latest revision it will say "Already up to date".

However you can checkout the latest revision again to undo your changes.

In root of your repo: git checkout . (Note the dot) Will checkout all files, and revert all your changes to the current revision.

git checkout path/to/a/file

Will checkout that file from the current revision. And revert that current file, also work with folders.

See: man git checkout for more info.

1

Pull is primarily a nice interface around fetch and associated commends such as sync and reset. To get the behaviour you want we have to drop down to the level below. As such try this to fetch and then clobber your working copy:

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df

Not the answer you're looking for? Browse other questions tagged or ask your own question.