Git rebase (Merge Squash) my feature branch onto another branch Git rebase (Merge Squash) my feature branch onto another branch git git

Git rebase (Merge Squash) my feature branch onto another branch


All you have to do is:

git checkout feature_branchgit rebase mastergit checkout mastergit merge --squash feature_branch

As the docs for git merge --squash say:

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a merge commit. This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

After that, you can git commit your changes which are already staged.


Here is what I do, gathered from a lot of experience working in larger teams:

# Get latest from mastergit checkout mastergit pull --rebase# rebase master into your feature branchgit checkout feature/my-featuregit rebase master --preserve-merges# merge feature into mastergit checkout master# DO ONLY ONE of the 2 options below# if you only have one or (maybe) 2 commits in your feature branchgit merge feature/my-feature# OR# this forces an empty merge commit (useful if we need to roll things back)git merge --no-ff feature/my-feature# if you use Github, this should also close the pull requestgit push origin master

Hope this helps!


I think you are looking for git merge --squash. It should bring in the commits from your feature branch into master and squashes them, so that you can create a single commit.