Github | fetch commit that not belong to branch

Viewed 1438

I opened a PR to some public repository in github,

In one of the comment's i got an improvement suggestion, with a link to commit. the commit is on top of my PR-branch HEAD. I want to merge it into my PR, but according to github this commit does not belong to any branch on this repository. .

Is there any way to fetch this commit and merge it into my branch?

1 Answers

What's happening here. You have a mybranch branch with a PR to merge it to mainbranch

a-b <- mainbranch (PR to merge into this)
   \
    1-2-3-x <- unreferenced commit (pushed improvement suggestion)
         \
          mybranch (your last commit)

In the above, your local repo only has commits a and b (on mainbranch) and 1, 2, and 3 (on mybranch). The suggestion is commit x, which is built off mybranch, but is only tagged (I think). It's not in a branch, per the message.

So, fetching pulls down commit x onto your PC, which allows you to operate on it locally.

Per the comment from Lasse, after fetching the commit, a git merge --ff-only SHA-OF-COMMIT will add it to your branch. This is telling git to merge, but with a "fast-forward" merge, which means basically mybranch just moves forward from commit 3 to commit x.

That is all happening locally, so a push of mybranch will push the new state of affairs up to Github, and your PR is automagically updated with the new commit.

Related