How to sync up your git dev branch after you've merged+squashed a PR to master, in GitHub?
So GitHub has the ability to merge+squash commits for a PR.
We follow the process of PR’ing code from
Previously, I’ve been just ‘merging’ the PR’s but that generates a new commit which says: “
Merge Pull Request #1 from foo/bar“. 🙁 Boooo…
So I thought I might try the new
Squash Commits thingy with GH. This created a new commit with all my previous commits squashed. Ok, so far so good.
I then went back to my
dev branch (on my developer machine) .. pulled down
upstream/master (which was where the PR and squash-merge happened)) and it now added another commit to my local history! It didn’t go “Oh .. wow. you’re waaay out of line .. lets sync up”. It just did a merge.
So the Squash+Merge button squashed 4 commits and replaced it with 1 …
upstream/master on my localhost machine now has my 4 commits still there AND the Squashed-commit the PR did AND a new commit which is “
Merge branch master .. blah ... noise ..spam” commit 🙁 🙁 🙁
Is there a special trick/workflow I should be doing after a merge-squash has occurred .. to make sure my
dev branch is properly sync’d? Like .. does everyone just delete their localhost
dev branch before they do a pull
upstream/master back down to their localhost and into a (newly created)
Remember: the goal here is to avoid those crappy “Merge Pull Request #2..” merge bubble messages.
Or are people just doing this via the CLI for the time being until GitHub learns how to do this 🙁
3 Solutions collect form web for “How to sync up your git dev branch after you've merged+squashed a PR to master, in GitHub?”
I think the problem is with your workflow: usually once you merge a pull request (no matter which method you use) you are then done with that branch. If you want to do further changes, you better create a new feature branch out of current upstream/master and later you could open another pull request to merge it back.
In case you really want to stick to a single long-lived branch for all development (the one you call dev), there are a few caveats you have to keep in mind:
- If you are not the only one working on that branch, you have to avoid any kind of history rewriting. No rebasing, no squashing, no resetting, not even amending commits. This basically rules out using squash merge.
- If you are sure you are the only one working on that branch, and you use GitHub’s squash option to merge pull requests as you did, then you must reset you local dev branch to latest upstream/master before resuming your work there. That also means that later you will need to force-push to upstream to create a new pull request.
The last point is error-prone and will affect previous code reviews so personally I would choose to just use short-lived feature branches.
dev branch was merged and squashed then you don’t need it anymore. Just reset it to
If there is some newer changes you can call
git rebase -i upstream/master instead and remove all commits which was merged, rebasing the rest.
There is a better solution for merging and squashing your commits without an extra commit saying “Merge Foo branch in Bar” . You should always prefer rebasing instead of merging and then squashing. So rebase will help you in merging two branches without any extra commit. You should try rebasing the branch instead of merging. Here is the detailed explanation for the same here.