Skip to content

Pull Request Procedure to synchronize unpublished with published

Blake Walsh edited this page Aug 13, 2020 · 1 revision

While in general changes and pull requests should be made against unpublished branch and then "forward propagated" into published, if a pull request is made against published branch (such as from a forked repository), here is how to keep the branches in sync.

First accept the pull request, using "Squash and merge", to condense the commits down to a single commit.

Now we need to make a new pull request, for unpublished branch:

git checkout unpublished
git pull
git checkout -b new-branch-name
git cherry-pick published # this assumes no new commit has been made in the meantime
git push --set-upstream origin new-branch-name

Now create a pull request from new-branch-name to unpublished

A note on cherry-pick

Due to how git works, the command git cherry-pick published does not, as you might expect, cherry pick every commit in the published branch, it only picks the commit that published branch points to (the latest commit).

As such the cherry pick command used above assumes that "Squash and Merge" was used so a single commit encompasses all the changes. If "rebase and merge" was used on a PR containing multiple commits, you will need to cherry pick all the commits. The easiest way to do this is probably using git-gui, but you can also try using a command that picks a range of commits:

git cherry-pick published~5^..published

Replacing '5' with the number of commits.

Using git-gui can be a good idea if it has been complicated by new commits being added in the meantime.