Merge conflicts updating from upstream

I’m trying to get started with git on a github project. (I’ve been using CVS, SVN and hg for years; git is hard to get my head around). I’m following the instructions as precisely as I can and simply cannot make it work.

I clone my forked project:

  • Changing the parent of a branch
  • Where to store differences between dev and production branch in git?
  • git multiple remotes: what to do with ignored/private files
  • Git branching and switching back to master is ahead?
  • Merging one change to multiple branches in Git
  • Git: Deny deleting remote branch via push (like receive.denyDeletes), but only if branch is not fully merged
  • git clone

    As recommended, I add an ‘upstream’ remote that tracks the project that my one is forked from:

    git remote add upstream

    I fetch from it:

    git fetch upstream

    All this works fine. But, it’s been a week or so since I forked the project, and upstream have been making changes. So I want to pull in those changes. I’m currently in the right branch — allwinner-v3.0-android-v2 — so I merge from upstream into my branch:

    git merge upstream/allwinner-v3.0-android-v2

    …and I get merge conflicts.

    CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby/common.h
    CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby/Makefile
    CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby.S
    CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/Makefile

    Now, I’ve checked in nothing; I haven’t started work yet, and my project is completely untouched since I forked it. Therefore it should not be possible to have any conflicts. But there are some; what’s going on, and how do I fix it?


    git show-branch HEAD upstream/allwinner-v3.0-android-v2 shows this, which I have to say I don’t understand a word of:

    ! [HEAD] arm: sun3i: add getioaddr macro
     ! [upstream/allwinner-v3.0-android-v2] arm: sun3i: updated irq handling and machine_desc to 3.0
     + [upstream/allwinner-v3.0-android-v2] arm: sun3i: updated irq handling and machine_desc to 3.0
     + [upstream/allwinner-v3.0-android-v2^] arm: sunxi: renable early_printk in all _defconfig except crane's
    +  [HEAD] arm: sun3i: add getioaddr macro
    +  [HEAD^] arm: sun3i: add dummy machine type

  • Resolve selected merge conflicts using p4merge in GIT
  • Error when trying to reset git HEAD
  • git history of a source line
  • When using git filter-branch, it duplicates my commit history and creates duplicate files. How do I get rid of this?
  • git - setting a commit's parent without rebase
  • can't push git's tag to remote as maven release process
  • 2 Solutions collect form web for “Merge conflicts updating from upstream”

    It could be, that upstream has rewritten history (rebase, amend, …) – they shouldn’t do that, but you’ll never know.

    Since you say you don’t have any local changes or commits, you should bring your repository back to a clean state by resetting your branch:

    git reset --hard upstream/allwinner-v3.0-android-v2

    (This will discard any local changes and make commits of current HEAD unreachable!)

    The above assumes that you will (force) push the newly reset state of your branch to your remote repository, otherwise you will encounter the conflicts again when you try to pull from origin.

    git push origin +allwinner-v3.0-android-v2

    If you already had committed yourself locally, you’d have to rebase (or cherry-pick) your commits on top of the upstream branch, and then do a push to origin. That way you will re-write your local history the same way upstream did and apply your changes on top, i.e.:

    git rebase --onto upstream/branch \
      last-original-upstream-commit-before-yours \

    The show-branch output means that upstream and HEAD have each added two commits since their common ancestor (assuming that’s the full output). (See also: If you haven’t committed anything yourself, that does mean that upstream pushed a rebase (or something else that changed the history). Since you haven’t committed anything, knittl’s answer is exactly what you want.

    For what it’s worth, I also love git log --oneline --graph --decorate --remotes --branches for this. You’ll get an ASCII graph with all your branches and remotes, so you can visualize what happened where.

    Git Baby is a git and github fan, let's start git clone.