0

I am trying to merge a pull request with my project, but it had conflicts. I download their branch and then went through each file and solved the conflicts, then I committed each file.

I followed the instructions here: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-using-the-command-line

At the end it says "You can now merge the branches on the command line or push your changes to your remote repository on GitHub and merge your changes in a pull request." but I don't understand what this means.

How do I merge the pull request with my resolved merge conflicts?

if I try to just git push i get this:

! [rejected] master -> master (fetch first) hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.`

stackers
  • 2,701
  • 4
  • 34
  • 66
  • you have two ways to solve. Please reference this [link](https://stackoverflow.com/questions/46692989/how-to-resolve-merge-conflict-in-pull-request-in-vsts). – Naing Apr 10 '20 at 02:27
  • it sounds like I want to "Merge from target to current branch prior to completing the PR" but it doesn't say what commands to use – stackers Apr 10 '20 at 02:48
  • You followed the wrong instructions. This is the page you want: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-on-github A merge conflict during a pull request is special, because github adds extra commits to the branch. – matt Apr 10 '20 at 02:53
  • 1
    that page says "Tip: If the Resolve conflicts button is deactivated, your pull request's merge conflict is too complex to resolve on GitHub. You must resolve the merge conflict using another Git client like Atom's Git integration or the command line. For more information see "Resolving a merge conflict using the command line."", which is the page i was originally on. I am trying to merge it via command line – stackers Apr 10 '20 at 02:58

2 Answers2

0

You should be able to push your changes, now including the merge resolution to your main repository

D. Melo
  • 2,139
  • 2
  • 14
  • 19
0

It's not entirely clear to me whether you used git fetch to obtain all of your and their commits so that everything was up to date all around, ran git merge locally, resolved all conflicts, and committed locally, or not.

If you did do all that, the error simply means that after you started the merging process, the GitHub repository where you got the most recent commits from, got some even more recent commits. You must now repeat some of the work you just did. You can keep the merge you made, and its resolutions, or just start over. If you start over, you'll generally have to re-make all the resolutions you made already, which is often rather painful, and of course, if this takes a while, this situation can easily happen again: The Git repository you're getting commits from, then merging your PR with, is a moving target, and you have to finish all your work before it moves again.

If you didn't do all that, then the problem is simply that you didn't do all that. Always make sure your own Git repository has all the commits that their repository has when you start: update your Git repository with:

git fetch origin

and use git log --all --decorate --oneline --graph or a graphical Git browser (gitk or any fancier one) to see how your branch names now stack up against your remote-tracking (origin/*) names. Make sure your master matches their master. Get the to-be-merged commits from the GitHub repository using git fetch refs/pull/number/head:to-merge or similar. (You may want to create a pr-number or pr/number branch locally to deal with multiple pull requests "at the same time", more or less.)

Not all of this is really very well described on the GitHub help pages, in my opinion, but setting up the proper background and then describing it properly takes a lot of words and examples.

torek
  • 448,244
  • 59
  • 642
  • 775