Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do a Git pull to overwrite local changes

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?

like image 733
Andre Avatar asked Jun 06 '11 20:06

Andre


People also ask

Does git pull update local files?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.


1 Answers

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.

like image 64
Seth Robertson Avatar answered Sep 28 '22 08:09

Seth Robertson