2

I want to git pull from the remote origin and want to keep my local changes and want to ignore remote changes in conflicted files only. Is there any way to do it by Git?

I have one option that I backup my local files and after pull, override them with the conflicted files. But I want to achieve this by using git.

Akshay Pethani
  • 2,390
  • 2
  • 29
  • 42
  • This is not an answer to your question but just a small hint. Are you doing backup manually ? I think you can use git stash for stashing local changes, pull the remote, pop the stash and accept yours during merge conflict. If you use intellij Idea for pulling the git remote, it will show an option called smart checkout where it will do stashing and unstashing automatically and during merge conflict you can choose to accept yours. – Praveen E Mar 14 '19 at 12:17
  • Have you already committed your local changes? – kapsiR Mar 14 '19 at 12:38
  • @kapsi Not I have not committed local changes. – Akshay Pethani Mar 14 '19 at 12:44
  • @PraveenE I am doing the backup manually. If I use to stash then it will try to merge the file. – Akshay Pethani Mar 14 '19 at 12:49
  • I got the answer from here: https://stackoverflow.com/questions/10414769/git-pull-keeping-local-changes – Akshay Pethani Mar 14 '19 at 15:11
  • @AkshayPethani Thanks for the information. For me `git checkout --theirs -- .` did not work for all files at once – kapsiR Mar 15 '19 at 06:13

2 Answers2

1

Instead of git pull, You can use git rebase to resolve conflict. It will not merge remote code into your branch, instead it will give one by one step to resolve conflicts.

Aman
  • 642
  • 1
  • 5
  • 12
0

With stash and merge this should work (I don't know if you want call this a dirty solution ):

  1. git stash
    Stash current changes (Maybe you need --include-untracked too)
  2. git pull
    Pull remote changes
  3. git merge -X theirs --no-commit --no-ff stash
    Merge stash into current branch (with changes from stash applied), don't commit and fast-forward
  4. git reset -- .
    Unstage changes
  5. git merge --abort
    Abort the merge operation
  6. git stash pop in case you need your untracked files too
kapsiR
  • 2,720
  • 28
  • 36