Using git, is there a good way to get the latest from upstream and re-apply our downstream changes? Instead of merging the upstream branch into the downstream branch that already contains our downstream changes, re-applying our downstream changes to the new upstream would be more efficient.
I have a situation I imagine isn't unique: we have changes in our downstream branch that the upstream won't or hasn't yet accepted, but we need to keep periodically getting (very large) upstream changes from a team much much larger (by orders of magnitude) than ours.
It is much better for us adapt our downstream code changes to the upstream changes - and not vice versa - since the other way would be much more work in the long run each merge. Re-applying our downstream changes (and adapting them to the new upstream) is much cleaner and safer than merging the upstream changes into our downstream changes, and allows us to better review how our downstream changes modify the new upstream.
The traditional merge upstream into downstream method would be:
git checkout origin/master
git merge upstream/master
, resolving conflicts between new upstream changes and our downstream changes
A labor-intensive method to re-apply downstream changes over the new upstream could be:
- Create a list of downstream changes to keep via
git log
- let's call it the keep list - Replace contents of origin/master with upstream/master: git command for making one branch like another
- git cherry-pick each old change from the keep list back into origin/master, resolving conflicts
One way of thinking about it - we need something similar to git rebase
but that works with "public" non-local branches, rebasing downstream/master using latest upstream/master. git rebase
itself is usually not acceptable since it would break the golden rule of rebasing - never rebase a "public" branch.
Anyone have a better method? Thanks in advance!