Morteza Shahriari Nia Morteza Shahriari Nia - 2 months ago 14
Git Question

Git combine commits before merge

I work at a branch called blaBla.

master
gets a ton of commits from other folks. To keep update blaBla with master I do frequent git pull master and merge it into blaBla. But this clutters my branch with a ton of commits. I want to merge all new commits that have happened in master into one and then merge it into my branch. So when I do
git log
I only see the commits that belong to that branch and those one single merge-commits. Nothing else

Answer

I want to merge all new commits that have happened in master into one and then merge it into my branch.

You really don't want to do this. The only reasonable options for bringing changes from master into a feature branch are:

  1. Do a normal git merge master without squashing its commits, so that Git can tell which commits your feature branch has in common with master (otherwise you will likely suffer from numerous merge conflicts). Otherwise all the new changes in your squashed merge commit will seem like they were part of your new feature - not good.

  2. Do a git rebase master to replay your branch's changes on top of the latest from master. This is my preferred workflow, as it structures your changes as "changes since master" regardless of which master you started with, but it comes with all the usual risks of rewriting history (e.g. communicate very carefully if you're going to git push --force to a branch that others are depending on).