Skip to content

[Docs][Github] explain how to rectify gh pr merge failure #66223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion llvm/docs/GitHub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,45 @@ You can also merge via the CLI by switching to your branch locally and run:

gh pr merge --squash --delete-branch

If you observe an error message from the above informing you that your pull
request is not mergeable, then that is likely because upstream has been
modified since your pull request was authored in a way that now results in a
merge conflict. You must first resolve this merge conflict in order to merge
your pull request. In order to do that:

::

git fetch upstream
git rebase upstream/main

Then fix the source files causing merge conflicts and make sure to rebuild and
retest the result. Then:

::

git add <files with resolved merge conflicts>
git rebase --continue

Finally, you'll need to force push to your branch one more time before you can
merge:

::

git push -f
Copy link
Member Author

@nickdesaulniers nickdesaulniers Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth noting that this may ask you to push potentially hundreds or thousands of patches and that this is OK.

Example.

Are you sure you want to push 248 commits? (y/N): y

This is fine, since you're pushing to a branch in your fork. The results can be seen at the bottom of #66003; only my 3 rebased commits are listed, not all 248 commits since I initially authored that PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in b86da6c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note to fellow reviewers, here's the error message you will observe if you do not update your PR with the rebased version:

$ gh pr merge --squash --delete-branch
! Pull request #66003 ([InlineAsm] wrap ConstraintCode in enum class NFC) has diverged from local branch
Message: Pull Request is not mergeable, Locations: [{Line:1 Column:58}]

and if you try to push (without -f):

$ git push
To github.com:nickdesaulniers/llvm-project.git
 ! [rejected]                  inlineasm_constraint -> inlineasm_constraint (non-fast-forward)
error: failed to push some refs to 'github.com:nickdesaulniers/llvm-project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

(though that is probably more obvious)

gh pr merge --squash --delete branch

This force push may ask if you intend to push hundreds, or potentially
thousands of patches (depending on how long it's been since your pull request
was initially authored vs. when you intended to merge it). Since you're pushing
to a branch in your fork, this is ok and expected. Github's UI for the pull
request will understand that you're rebasing just your patches, and display
this result correctly with a note that a force push did occur.


Checking out another PR locally
-------------------------------
Sometimes you want to review another person's PR on your local machine to run
tests or inspect code in your prefered editor. This is easily done with the
tests or inspect code in your preferred editor. This is easily done with the
CLI:

::
Expand Down