Search code examples
gitgithubversion-controlgit-fork

forking off of a pull request with git/github


I am working on a project in github. A user has created a pull request. I would like to fork off of this pull request. How do I do this? I can't see anything that immediately stands out to me in git documentation, but I am fairly certain this is possible...


Solution

  • I have the original repo forked already. How would I bring the PR into my fork and branch off of it?

    1. If you haven't already, clone your fork so that you have a local copy of your fork on your machine.

    2. Add the repo from whence the PR comes as a remote to your clone:

      git remote add the-pr-repo [email protected]:the-pr-user/the-pr-fork.git
      
    3. Checkout the PR's branch into your local repo:

      git fetch the-pr-repo
      git checkout the-pr-branch
      

    Now you've got a copy of the PR's branch in your local repo, and you can build, test, whatever.

    This is a PR for upstream.

    The PR still really just points to a branch. "Pull request" is literally a request to pull the commits from a given branch into some other branch. So let's say the PR is made from a repo called basil and specifies a branch called basils-changes, and the PR asks that the commits from basils-changes be added to the master branch of the upstream repo. I can easily get those same changes by first making sure that I have a local branch that's up to date with upstream/master, and then pulling basil/basils-changes into my local branch. That'll give me exactly what upstream/master will have if the PR is merged, so I can test the changes locally to decide whether I want merge the PR into upstream/master.