Search code examples
gitgithubgit-fork

How do I checkout a PR from a fork?


I'm using GitHub to host some projects and someone forked my repo and submitted a PR. I have never had to test a PR in a fork before. How can I checkout the branch and test it? Can I some how pull it into my repo? Or do I checkout the fork and test the branch that way?


Solution

  • There are a couple different ways but I’ll go over what I would do in this situation

    git remote add <whatever you want the remote to be called> <link to the fork>

    Here is the documentation. This will allow you to add and check out the remote branch from the fork. When reviewing PRs in the workflow you described I usually do a git clean -dfx (warning: this is a very intensive clean that gets rid of unstaged work you have), git remote add <whatever you want the remote to be called> <link to the fork>, and git checkout <branch name>.

    If it’s in your repo already you can see that with git branch -a and simply check it out as you might otherwise.