Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pull from github and keep local file without resolving merge conflicts

Tags:

git

merge

github

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

like image 940
Ryan Perera Avatar asked Apr 22 '26 10:04

Ryan Perera


2 Answers

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
like image 176
VonC Avatar answered Apr 25 '26 03:04

VonC


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
like image 28
GoZoner Avatar answered Apr 25 '26 04:04

GoZoner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!