Skip to content

Work on someone else's PR

Amaury Dehecq edited this page Apr 27, 2023 · 3 revisions

A little reminder for how to do this with git.

First, define the remote fork of your collaborator locally, for instance calling it amaury:

> git remote add amaury https://github.com/adehecq/xdem.git

which should now appear in your remotes:

> git remote -v

amaury	https://github.com/adehecq/xdem.git (fetch)
amaury	https://github.com/adehecq/xdem.git (push)
erik	https://github.com/erikmannerfelt/xdem.git (fetch)
erik	https://github.com/erikmannerfelt/xdem.git (push)
origin	https://github.com/rhugonnet/xdem.git (fetch)
origin	https://github.com/rhugonnet/xdem.git (push)
upstream	https://github.com/GlacioHack/xdem.git (fetch)
upstream	https://github.com/GlacioHack/xdem.git (push)

Then, fetch the fork.

> git fetch amaury --prune

remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 33 (delta 20), reused 30 (delta 19), pack-reused 0
Unpacking objects: 100% (33/33), 28.14 KiB | 588.00 KiB/s, done.
From https://github.com/adehecq/xdem
 * [new branch]      coreg               -> amaury/coreg
 * [new branch]      fix_geoutils_update -> amaury/fix_geoutils_update
 * [new branch]      main                -> amaury/main

And move to the desired branch (the one the PR is opened on), as you would do working on upstream. Doing this will give you a detached HEAD warning, which is normal.

> git checkout amaury/fix_geoutils_update 

Note: switching to 'amaury/fix_geoutils_update'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

Finally, add and commit you changes normally. Then, to push directly to that fork the following way:

> git push amaury HEAD:fix_geoutils_update