3

I want to pull from the github master full to update my current working directory. There is a file i've worked on called form.html which exists in my working directory and an older version on the github origin master branch.

 git pull origin master

When pulling from the master Im asked to resolve conflicts. I do not want to resolve merge conflicts but instead want my file form.html from my local branch to completely replace the form.html on the origin master branch (remote)

Whats the best way to achieve this ? thanks

Ryan Perera
  • 115
  • 1
  • 9

2 Answers2

6

If you haven't committed your local file, you could (following the idea of "git pull keeping local changes"):

git stash
git pull
git stash pop
# if conflict on pop:
git checkout --theirs -- form.html

But if your file is committed, then see "Is it possible to exclude specific commits when doing a git merge?", and, with a .gitattributes, declare the proper merge:

form.html merge=ours
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • whats the effect of git checkout --theirs -- form.html ? – Ryan Perera Mar 24 '13 at 00:17
  • 2
    @RyanPerera in case of conflict during the `stash pop`, a `checkout --theirs` makes sure you get back what you have stashed, and not what you have pulled. It will overwrite the modifications introduced by the pull with what you have saved. – VonC Mar 24 '13 at 00:40
1

Assuming you've committed your form.html file...

After you've performed 'git pull origin master' and have conflicts, at that point you can easily resolve the conflicts based on your local version. Do the following after the pull:

git checkout --ours -- <files in conflict>
git add <files in conflict>
git commit -m 'resolved with --ours'
git push origin master
GoZoner
  • 67,920
  • 20
  • 95
  • 145