Search code examples
gitgit-mergegit-remote

How to force merge two remote branches locally?


I'm trying to merge my local branch from a different repository to my upstream code. I would like to merge priv/dev branch to origin/master in my development system. I want to prioritize my changes over the origin master. However it's failing, Is there a mistake in my code?

git clone https://github.com/production public_code
cd public_code
git remote add priv https://gitlab.com/tmv/development
git merge -Xours priv/dev origin/master

Output

error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

Solution

  • Since you just cloned the one repo, you only need to do a regular merge:

    git clone https://github.com/production public_code
    cd public_code
    git remote add priv https://gitlab.com/tmv/development
    git merge -Xtheirs priv/dev
    git push origin HEAD
    

    After cloning, the master branch will already be checked out, and you will already have the latest in master.