Make git pull --rebase preserve merge commits

Viewed 8117

git pull --rebase removes unpushed merge commits. Is there a way to make it preserve them?

Say my history looks like—

A
| \ 
B  H
|  |
C  G
|  |
D  F
| /
E

(A being the merge commit.)

After a git pull --rebase it becomes—

H
|
G
|
F
|
X
|
B
|
C
|
D
|
E

(X being the new commits git pull --rebase inserted into my history.)—A is removed.

I know you can use git rebase --preserve-merges to preserve them with git rebase, but I don't see a way to preserve them with git pull --rebase.

4 Answers

Since git v2.22.0, --preserve-merges option has been deprecated in favor of --rebase-merges (to be used in combination with --interactive option) to reapply commits on top of another base tip with git-rebase:

git fetch origin master
git rebase --interactive --rebase-merges origin/master 
Related