Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve conflicts using remote changes when pulling from Git remote

Tags:

git

git-pull

I'm trying to pull code from my GitHub repo onto my server, but the pull keeps failing because of merge conflicts. I don't want to keep any of the changes that may have occurred on my local server since the last pull.

So is there a way I can force Git to overwrite with whatever version is in GitHub, rather than bother me about conflicts?

like image 741
David Tuite Avatar asked Jan 24 '11 17:01

David Tuite


People also ask

How do I pull changes from a remote GitHub?

Fetching changes from a remote repositoryUse git fetch to retrieve new work done by other people. Fetching from a repository grabs all the new remote-tracking branches and tags without merging those changes into your own branches. Otherwise, you can always add a new remote and then fetch.


1 Answers

If you truly want to discard the commits you've made locally, i.e. never have them in the history again, you're not asking how to pull - pull means merge, and you don't need to merge. All you need do is this:

# fetch from the default remote, origin git fetch # reset your current branch (master) to origin's master git reset --hard origin/master 

I'd personally recommend creating a backup branch at your current HEAD first, so that if you realize this was a bad idea, you haven't lost track of it.

If on the other hand, you want to keep those commits and make it look as though you merged with origin, and cause the merge to keep the versions from origin only, you can use the ours merge strategy:

# fetch from the default remote, origin git fetch # create a branch at your current master git branch old-master # reset to origin's master git reset --hard origin/master # merge your old master, keeping "our" (origin/master's) content git merge -s ours old-master 
like image 153
Cascabel Avatar answered Sep 23 '22 18:09

Cascabel