Do a Git pull to overwrite local changes

Andre picture Andre · Jun 6, 2011 · Viewed 22.1k times · Source

There has certainly been posts around for this, but I actually did a commit because I thought it was the right thing to do.

So, I have two repositories, one development and one production. I had to edit something in the production because it was an urgent bugfix, and now I have three files that are newer in the production than in the development.

I committed the three files on the production and tried a pull, but it told me there were merge errors. I tried copying and pasting the new files to the development server and retrying the whole thing and it didn't work. Now I'm sure that what I need is on the development (since I copied and pasted into it) and committed, so how could I pull and overwrite the conflicting files?


---- Following up to @Seths reply

Ok, I guess I do need to reword my question :) I have three repositories. One development, one in GitHub and one production. Usually to update production I just do a push from development to GitHub, git pull origin master (from GitHub to production), and it works.

Unfortunately, I changed files on production without stashing. How do I force overwrite instead of merge when trying a pull?

Answer

Seth Robertson picture Seth Robertson · Jun 6, 2011

If you want to entirely replace your local branch foo with the contents of the remote branch origin/foo:

git fetch origin
git checkout foo
git reset --hard origin/foo

If you want to do something else, please reword your question. However, I might add the production Git repository as a remote and then merge the live changes in, instead of whatever you tried.