How do I update my local copy of a pull request?

Magnus Ihse Bursie magnus.ihse.bursie at oracle.com
Thu Mar 11 15:56:39 UTC 2021



On 2021-03-04 16:44, Volker Simonis wrote:
> Hi,
>
> every PR request has the following instruction for downloading it locally:
>
> $ git fetch https://git.openjdk.java.net/jdk pull/2570/head:pull/2570
> $ git checkout pull/2570
>
> That works well for the first time. But what do I have to do if the PR
> was updated with more commits (or force-pushed with a new version).
>
> While on the local branch "pull/2570" another "git fetch
> https://git.openjdk.java.net/jdk pull/2570/head:pull/2570" fails with:
>
> fatal: Refusing to fetch into current branch refs/heads/pull/2570 of
> non-bare repository
>
> If I switch to another branch first (i.e. "git checkout master") the
> second "fetch" completes successfully (but I have to switch back to my
> pull/2570 branch afterwards).
>
> Instead of issuing a second fetch command on my "pull/2570" branch, I
> tried a simple "git pull" which returns:
>
> There is no tracking information for the current branch.
> Please specify which branch you want to merge with.
> See git-pull(1) for details.
>
>      git pull <remote> <branch>
>
> If you wish to set tracking information for this branch you can do so with:
>
>      git branch --set-upstream-to=<remote>/<branch> pull/2570
>
> The first advice is good, because "git pull
> https://git.openjdk.java.net/jdk pull/2570/head" will indeed update my
> branch. But the second advice (i.e. set tracking information for the
> pull request branch) doesn't seem to work:
>
> git branch --set-upstream-to=https://git.openjdk.java.net/jdk/pull/2570/head
> pull/2570
> error: the requested upstream branch
> 'https://git.openjdk.java.net/jdk/pull/2570/head' does not exist
> hint:
> hint: If you are planning on basing your work on an upstream
> hint: branch that already exists at the remote, you may need to
> hint: run "git fetch" to retrieve it.
>
> Doing a "git fetch https://git.openjdk.java.net/jdk pull/2570/head" as
> advised succeeds, but unfortunately doesn't fix the problem with
> "--set-upstream-to...".
>
> So to cut a long story short, it seems the simplest way of updating
> the local copy of a pull request is to run "git pull
> https://git.openjdk.java.net/jdk pull/2570/head". If this isn't
> something totally obvious, maybe we could at it to the "Download"
> information at the end of each pull request?


Perhaps something like this:
---


      Download

To checkout this PR locally:

|$ git fetch https://git.openjdk.java.net/jdk pull/2930/head:pull/2930|
|$ git checkout pull/2930|

|
|

To update a local copy with changes in the PR:

|$ git pull https://git.openjdk.java.net/jdk pull/2930/head|||

||

---

Does that seem okay?

> And there are still two remaining questions:
>
> 1. Why can't I set an upstream for the local pull request branch?
Beats me.

I've struggled with this as much as you have, but in contrast with you, 
I just gave up. :-)

/Magnus

>
> 2. Why do all the instructions mention
> "https://git.openjdk.java.net/jdk" instead of
> "https://github.com/openjdk/jdk/". This always gives me the warning
> "warning: redirecting to https://github.com/openjdk/jdk/". Might this
> also cause other problems?
>
> Thank you and best regards,
> Volker



More information about the skara-dev mailing list