Steve Chambers Steve Chambers - 1 month ago 15
Git Question

How to create a single commit with the differences between the local and remote Git repositories?

In Git, let's say I've been working on a local branch:

Common ancestor
/\
A \
/ X
B \
/ Y
C remote
local


I made local commits A, B and C and in the mean time the remote branch moved on with commits X and Y. So I do a pull and get:

Common ancestor
/\
A \
/ X
B \
/ Y
C /remote
\ /
\ /
\ /
\/
M
local


If I now push, the remote history will include all my A, B, C and M commits... but this isn't what I want.

I want to just push a single commit with the differences from my local branch so the remote branch will just look like this with none of the merging complexity:

Common ancestor
\
\
X
\
Y
\
N
remote


How can I achieve this?

Answer

Do a

git pull --rebase

Which is equivalent to git fetch and a git rebase instead of a git merge.