I have been using squash with the steps below and I find it really time consuming and error prone
git rebase upstream/develop
git merge-base mylocaldev upstream/develop (this will display a commit hash that can be used in the next step)
git rebase -i (hash from last step).
(now in vi leave first line as "pick" and change the other line to "squash").
(vi launches again, I can clean up commit message then save).
git push -f origin mylocaldev
Very often I have to resolve multiple conflicts in the process. (What I don't understand is if I don't do the local squash, push it to my origin, open a PR between my origin and upstream, there I have the github option to squash, and it NEVER needs me to resolve any conflict as long as my branch has the latest changes from upstream).
What am I missing in my local workflow that github does in its squash process?
I am wondering if there is a better practice/workflow I can use (to have similar effect as squash)? or at least something I can use to avoid resolving conflicts.
Thanks!
It looks like you are trying to turn the many commits of
mylocaldev, which was branched fromupstream/develop, into a single commit that comes off the end ofupstream/develop.For example you wish to turn this:
into this:
The way to do that is to do it in the opposite order from what you're doing:
Do the above only once while working on the same local branch. Merge conflicts are extremely likely if you keep a branch alive and rebase it multiple times onto the same branch as the latter grows independently. The reason is that the merge-base does not move as a result of the rebase, so if you rebase multiple times in this way, you are replaying against more and more new commits that keep appearing on the target branch — including your own! — which is a golden recipe for merge conflicts.
Because the thing that happens in GitHub happens only once. They warn you quite loudly in their docs not to use a "squash and merge" multiple times off the same branch.