Skip to content

Provide guidance on editing PRs prior to merge #129

Closed

Description

@ncoghlan

The GitHub "command line instructions" for PR merging assume you'll be merging and pushing changes from the command line rather than amending the original PR. This means I'm not entirely clear on how to amend the following prior to accepting someone's change:

  • update ACKs
  • add a NEWS entry
  • add a What's New entry
  • any other tweaks I want to just fix myself rather than pushing back for another round of review

https://help.github.com/articles/committing-changes-to-a-pull-request-branch-created-from-a-fork/ seems to be the main documentation for this, but making a full clone for this purpose seems a little excessive given the size of the CPython repository.

I'm going to try using a shallow clone for the purpose: https://www.perforce.com/blog/141218/git-beyond-basics-using-shallow-clones

Activity

  1. warsaw commented on Feb 22, 2017

    @warsaw
    Member

    It's an interesting problem that I run into in other projects. I don't want to necessarily block a merge because things like a NEWS file entry are missing, but then I also don't like merging a branch that's missing the things you mention above. I'll usually use the command line to fetch their branch, clean it up, then either push it to master (not an option for CPython repo) or push to a new branch, CI that and land that without squash merging (so the original work is preserved). Not super ideal though.

  2. ncoghlan commented on Feb 22, 2017

    @ncoghlan
    ContributorAuthor

    Using python/cpython#171 as my example, it looks like the following command gives me a shallow clone with the PR contents:

    git clone -b bpo-26128 --depth=1 git://github.com/Ghost-script/cpython.git
    

    (The branch name and repo URL can be accessed by looking at the "command line instructions" on the PR)

    Next step will be to actually push the update with the Author overridden to match the original contributor.

  3. ncoghlan commented on Feb 22, 2017

    @ncoghlan
    ContributorAuthor

    OK, after trying it, the shallow clone idea is a non-starter, since you'll need the full history if you actually want to rebase the PR branch (which is likely to be essential for the time being, in order to edit and push Misc/NEWS without conflicts).

    I'm going to try a different approach making a fresh clone of my local repo (so "origin" is my own main working copy rather than anything on GitHub) and then pulling the PR branch into that by setting up the contributor's fork as a new remote.

  4. ncoghlan commented on Feb 22, 2017

    @ncoghlan
    ContributorAuthor

    This worked better for making a local branch that I could rebase:

    git remote add Ghost-script git://github.com/Ghost-script/cpython.git
    git fetch Ghost-script
    git checkout -b bpo-26128 --track Ghost-script/bpo-26128
    

    However, I couldn't actually push the resulting rebase back to the original branch.

  5. Carreau commented on Feb 22, 2017

    @Carreau

    you can set the following in your (global) .gitconfig:

    $ cat ~/.gitconfig
    [remote "origin"]
    	fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
    

    That allows you to

    $ git fetch 
    $ git checkout origin/pr/XXX
    

    (update to your liking the naming scheme) which is useful to at least checkout without having to add the remote. I haven't figured out how to push to a PR without setting a remote, but that helps.

    However, I couldn't actually push the resulting rebase back to the original branch.

    It does that to me as well, I had to switch git:// to ssh:// (and --force if I rebase).

    I would recommend trying hub (and aliasing it to git) that set most of that up automatically.

  6. ncoghlan commented on Feb 22, 2017

    @ncoghlan
    ContributorAuthor

    I use git hosts other than GitHub, so I have no intention of adopting a GitHub specific client.

  7. Carreau commented on Feb 22, 2017

    @Carreau

    I use git hosts other than GitHub, so I have no intention of adopting a GitHub specific client.

    hub does work with non-github client, it just add commands that work only with github. But understandable.

  8. ncoghlan commented on Feb 23, 2017

    @ncoghlan
    ContributorAuthor

    After comparison with my main CPython checkout, I found the right remote definition to enable updating contributor PRs:

    git remote add Ghost-script git@github.com:Ghost-script/cpython.git
    git fetch Ghost-script
    git checkout -b bpo-26128 --track Ghost-script/bpo-26128
    

    And then a rebase of the PR on master looks like:

    git rebase origin/master
    git push Ghost-script -f
    

    So given that, you can edit the PR as needed on the contributor's branch, push the updates back to their repo, and then accept the amended PR via squash & merge.

  9. Carreau commented on Feb 23, 2017

    @Carreau

    If put in the dev guide, I would suggest --force-with-lease instead of -f, potentially git config --global alias.pushf "push --force-with-lease" once to avoid the long option. It force pushes only if remote have not changed in the meantime.

  10. ncoghlan commented on Feb 23, 2017

    @ncoghlan
    ContributorAuthor

    Oh, nice, I didn't know about --force-with-lease. I agree, that would be a much better option when rebasing a shared PR branch.

  11. methane commented on Feb 23, 2017

    @methane
    Member

    While I love rebase at my private branch (no one other than me push to it),
    I don't like using -f or --force-with-lease on branch shared by more than two people.
    It may make trouble, and contributor may not git expert.

    So if solving conflict is required, I prefer merge to rebase.
    merge commit will be removed when "Squash and merge".

  12. ncoghlan commented on Feb 23, 2017

    @ncoghlan
    ContributorAuthor

    That makes sense, and would make that part of the instructions just:

    git merge origin/master
    git push Ghost-script
    

    With a note clarifying that the later squash & merge will remove the interim merge commit.

  13. Mariatta commented on Mar 17, 2017

    @Mariatta
    Member

    Must admit I don't know how to properly edit other people's code too, and I know I'm not the only one.
    Can anyone who has done this successfully, write it up in the devguide? Please? Thanks :)

  14. self-assigned this
    on Mar 18, 2017
  15. ncoghlan commented on Mar 18, 2017

    @ncoghlan
    ContributorAuthor

    Ah, you just reminded me I promised @nayafia a write-up of the specifics of the documentation problem here, so I should be able to tackle both of those at the same time.

  16. added a commit that references this issue on Mar 18, 2017
  17. ncoghlan commented on Mar 18, 2017

    @ncoghlan
    ContributorAuthor

    PR submitted here: #150

    I think the main requirement before merging that is for someone else (@Mariatta?) to actually try them out and confirm that I didn't miss anything when transcribing the steps I took to edit python/cpython#171

    I used merging in master as an example of a change to make, since it came up above, and let me gloss over all the details of making changes, adding them, and committing them with an appropriate message (plus it's important as long as we're still editing Misc/NEWS directly).

  18. Mariatta commented on Mar 18, 2017

    @Mariatta
    Member

    Nice! Thanks :)

  19. ncoghlan commented on Mar 19, 2017

    @ncoghlan
    ContributorAuthor

    @Mariatta suggested attempting to define a git alias for this (akin to the git PR one) in order to avoid having to write out the following 3 commands every time:

    $ git remote add <contributor> git@github.com:<contributor>/cpython.git
    $ git fetch <contributor>
    $ git checkout -b <branch_name> --track <contributor>/<branch_name>
    

    @zware pointed out that given a suitable "push" command, it's possible to re-use the existing git pr alias:

    $ git pr 150
    # edit, commit
    $ git push git@github.com:ncoghlan/devguide pr_150:issue-129-edit-contributor-pr-branches
    

    If we assume the local branch is named after the PR number, then it would be possible to define a relatively straightforward alias for a push like:

    $ git pr-amend 150 ncoghlan issue-129-edit-contributor-pr-branches
    
  20. Mariatta commented on Mar 22, 2017

    @Mariatta
    Member

    I was able to edit @ncoghlan PR #150 by following the steps mentioned there 🎉

    I updated the instructions to recommend using git pr alias, but did not create git pr-amend alias.

  21. added a commit that references this issue on Mar 22, 2017
  22. ncoghlan commented on Mar 22, 2017

    @ncoghlan
    ContributorAuthor

    I merged the PR with @Mariatta's edits, so closing this - if folks are using this enough to want a git alias, the instructions for creating the pr alias are already there, and adapting them should be relatively straightforward.

  23. added a commit that references this issue on Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions