There are some methods to apply the code from a pull request (PR) to a base branch.
E.g., if you want to test this PR, you can use the GitHub CLI and this command in your local repository.
gh pr checkout 3
But this only works at GitHub, so you can do something similar, and valid for different places, using the patch from the PR.
Table of Contents
Getting the patch
If you add the “.patch” text to the PR URL, you are going to get the patch file from this PR:
- PR: https://github.com/amieiro/GlotPress/pull/3
- Patch: https://github.com/amieiro/GlotPress/pull/3.patch
You can do something similar with the content from an individual commit, not from all commits of a PR:
- Commit: https://github.com/amieiro/GlotPress/pull/3/commits/17976dbece9f73b392e23d21c8e8285739194ef4
- Patch: https://github.com/amieiro/GlotPress/pull/3/commits/17976dbece9f73b392e23d21c8e8285739194ef4.patch
Applying the patch
To apply one of this patches to the current branch, you can get the patch with curl
or with wget
and then apply the patch:
curl -L -O https://github.com/amieiro/GlotPress/pull/3.patch wget https://github.com/amieiro/GlotPress/pull/3.patch
And then you can apply the patch
git apply 3.patch
Finally, you need to remove the patch file:
rm 3.patch
Applying the patch in one step
You can do the whole process in one step, using Unix pipes with curl:
curl -L https://github.com/amieiro/GlotPress/pull/3.patch | git apply -v
Or with wget:
wget -q -O - https://github.com/amieiro/GlotPress/pull/3.patch | git apply -v
In both situations, you don’t need to remove any local file.
Another relevant servers
You can do the same with another relevant players, like GitLab, Bitbucket,…
GitLab
To obtain the patch, you need to add the .patch text to the URL.
- PR: https://gitlab.com/inkscape/inkscape/-/merge_requests/4360
- Patch: https://gitlab.com/inkscape/inkscape/-/merge_requests/4360.patch
Bitbucket
To obtain the Bitbucket patch, you need to use a URL like this: https://bitbucket.org/api/2.0/repositories/GROUP/PROJECT/pullrequests/ID/diff (more info here).