Skip to content

Commit 23a00fc

Browse files
committed
Merge bitcoin/bitcoin#32783: doc: Add fetching single PRs from upstream to productivity.md
45b1d39 doc: Add fetching single PRs from upstream (will) Pull request description: Current recommendation is to add a new remote fetching all PRs, but this is resource-intensive. Document a better way to fetch a single PR, and to update a PR which has been force-pushed. Follows up on a [comment from 32774](bitcoin/bitcoin#32774 (comment)) ACKs for top commit: pablomartin4btc: re-ACK 45b1d39 achow101: ACK 45b1d39 janb84: re ACK 45b1d39 theStack: ACK 45b1d39 Tree-SHA512: 3af02aa1335fd941538fabaa527bcfa92907dc6c272e72bc37ca38211b8aeebf32dd1837f976308058360ed1364fec749b49213f2b8bc4e35542da55a7bd30e1
2 parents 6e5b67a + 45b1d39 commit 23a00fc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/productivity.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,37 @@ As an alternative to fetching commits directly, when looking at pull requests by
185185

186186
This will add an `upstream-pull` remote to your git repository, which can be fetched using `git fetch --all` or `git fetch upstream-pull`. It will download and store on disk quite a lot of data (all PRs, including merged and closed ones). Afterwards, you can use `upstream-pull/NUMBER/head` in arguments to `git show`, `git checkout` and anywhere a commit id would be acceptable to see the changes from pull request NUMBER.
187187

188+
### Fetch and update PRs individually
189+
190+
The refspec remote is quite resource-heavy, and it is possible to fetch PRs singularly from the remote. To do this you can run:
191+
192+
```bash
193+
# Individual fetch
194+
git fetch upstream pull/<number>/head
195+
196+
# Fetch with automatic branch creation and switch
197+
git fetch upstream pull/<number>/head:pr-<number> && git switch pr-<number>
198+
```
199+
200+
...from the command line, substituting `<number>` with the PR number you want to fetch/update.
201+
202+
> [!NOTE]
203+
> The remote named "upstream" here must be the one that the pull request was opened against.
204+
> e.g. github.com/bitcoin/bitcoin.git or for the GUI github.com/bitcoin-core/gui
205+
206+
Make these easier to use by adding aliases to your git config:
207+
208+
```
209+
[alias]
210+
# Fetch a single Pull Request and switch to it in a new branch, with `git pr 12345`
211+
pr = "!f() { git fetch upstream pull/$1/head:pr-$1 && git switch pr-$1; }; f";
212+
213+
# Update a Pull Request branch, even after a force push, and even if checked out, with `git pru 12345`
214+
pru = "!f() { git fetch --update-head-ok -f upstream pull/$1/head:pr-$1; }; f";
215+
```
216+
217+
Then a simple `git pr 12345` will fetch and check out that pr from upstream.
218+
188219
### Diff the diffs with `git range-diff`
189220

190221
It is very common for contributors to rebase their pull requests, or make changes to commits (perhaps in response to review) that are not at the head of their branch. This poses a problem for reviewers as when the contributor force pushes, the reviewer is no longer sure that his previous reviews of commits are still valid (as the commit hashes can now be different even though the diff is semantically the same). [git range-diff](https://git-scm.com/docs/git-range-diff) (Git >= 2.19) can help solve this problem by diffing the diffs.

0 commit comments

Comments
 (0)