Search code examples
gitgithubopen-source

Conflict in merging from upstream


I am working on an open source project with a company. I forked their repo and cloned the repo on my machine and set my master branch to track company's original repo. I started working on the project and made some changes in a new branch. In the meanwhile, the organization made around 1000 commits. Now when I want to merge my master with upstream using the command :

git fetch upstream

git merge upstream/master

The git console shows the following error for multiple files.

Auto-merging file-path CONFLICT (add/add): Merge conflict in file-path

To push my changes i need to first merge my master with upstream and then my working branch with master.

How do i fix this issue or if its not fixable. Can anyone help me with where I went wrong so that I do not commit the same mistake again.


Solution

  • looks to me that the surprise is that your master doesn't have a clean merge from their master. You expect that there isn't any change that you made in your local master since all your changes are in a branch that you are working on, so "merging" their master into your master should be a simple "fast-forward". But git seems to disagree and it apparently sees some divergence between your master and their master.

    If I got all this right, and you are sure that there is nothing interesting in your local master than I would simply run from branch master

    git reset upstream/master --hard
    

    now you can worry aobut merging your branch into master

    git merge my_branch
    

    and resolve the actual conflicts between your work and their 1000 commits

    if you'd like to see where is it that git thinks that you diverged from their mast you may run

    git merge-base upstream/master
    

    chances are that you made 1 or 2 commits on master and then git checkout -b mybranch. If that's the case than your work is safe on your branch and you need not worry of losing these commits that you accidentally made on your local master.