GIT Tutorial: Fetching and Testing Pull Request Branches Locally
There are a lot of times when you’re using Git and BitBucket in a work environment and you want to be able to test someone’s PR branch without having to download a patch or clone it. Here’s a nifty trick that will allow you to fetch and checkout PR branches on your master repo without having to clone or patch from BitBucket.
1. Add your remote master as an upstream
git remote add upstream ssh://email@example.com
2. Change your new remote to fetch from your pull requests instead of regular branches
git config --add remote.upstream.fetch '+refs/pull-requests/*/from:refs/remotes/upstream/pr/*'
3. Now fetch the PR branches that are currently available in your repo
git fetch upstream
4. Finally, you can use the ID of the PR you want (the ID will be available in the URL of the link to the PR) and simply checkout the PR with that ID number by replacing ID with the number of the PR in the code snippet below.
git checkout upstream/pr/ID
5. Voila! You’ve now downloaded a PR branch to your local git instance and can run it like you would for any other branch.