Joel Broström
Joel Broström

Reputation: 4080

How to edit a PR from third party fork before merging (and not take credit for their code)?

  1. I am a collaborator to a GitHub repository.
  2. Some one forks it, adds a feature, and creates a PR.
  3. I ask them to add documentation and an example but they don't have time.
  4. They ask me to do it, and then merge the PR.

I could just copy the code and make a new PR with the added docs etc. but then I would get all the credit for the code.

How do I do it the right way?

Upvotes: 3

Views: 438

Answers (2)

peterevans
peterevans

Reputation: 42160

Another option that I've used myself before when in a similar situation is to edit the PR and change the base from master to a temporary branch. Then merge the PR to the temporary branch, make whatever changes you need to and raise a new PR to merge into master. This will retain the original commits by the contributor.

Another pattern is to merge to a temporary branch and then cherry pick commits by the contributor to a new branch or directly to master. Cherry picking also retains the contributor of the commit as the author. You (the collaborator) will be shown as the committer. The link below is an example commit showing what that looks like.

https://github.com/peter-evans/create-pull-request/commit/062968931cd601fdcb4b8b0a2e21b69e0ef43812

Upvotes: 1

Philippe
Philippe

Reputation: 31187

If you're a collaborator of the GitHub project, you have, by default, the rights to push directly commits to the branch that is used to do the pull request.

This is the settings enabled by default when you do a PR:

rights to edit PR

So, you have just to add a remote and push to it. Even if it's better to communicate about it (I did it some rare times and that completely loose some git beginners that have difficulties)

Or you could merge it and do the fix after.

Upvotes: 2

Related Questions