Privacy Policy
Snippets index

  Github: Checking out pull requests locally

  • Find the ID number of the pull request. This is the sequence of digits right after the pull request's title.

  • Fetch the reference to the pull request based on its ID number, creating a new branch in the process:

    $ git fetch origin pull/ID/head:BRANCHNAME
    
  • Switch to the new branch that's based on this pull request:

    $ git checkout BRANCHNAME
    
  • At this point, you can do anything you want with this branch. You can run some local tests, or merge other branches into the branch.

When you're ready, you can push the new branch up:

$ git push origin BRANCHNAME

Without creating a local branch

You might prefer to fetch and checkout without creating a local branch and to be in HEAD detached state.

This allows you quickly to check the pull request without polluting my local machine with unnecessary local branches.

git fetch upstream pull/ID/head && git checkout FETCH_HEAD

where ID is a pull request ID and upstream where is original pull request has been created (it could be origin, for example).