3

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.

6
  • 1
    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. Commented Mar 14, 2019 at 12:17
  • Have you already committed your local changes? Commented Mar 14, 2019 at 12:38
  • @kapsi Not I have not committed local changes. Commented Mar 14, 2019 at 12:44
  • @PraveenE I am doing the backup manually. If I use to stash then it will try to merge the file. Commented Mar 14, 2019 at 12:49
  • I got the answer from here: stackoverflow.com/questions/10414769/… Commented Mar 14, 2019 at 15:11

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.