Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid merge commit in git

Tags:

git

merge

rebase

My local repo was looking like that before I had to pull:

[my commit 3] <- to be pushed
[my commit 2] <- already pushed
[my commit 1]

So I pulled and had to do a merge because there were conflicts, which I commited locally:

[merge commit] <- created that by resolving conflicts
[new commit from coworker] <- pulled that
[my commit 3]
[my commit 2]
[my commit 1]

Now my questions is how I can get rid of the merge commit at the top. I think it should look like that:

[my commit 3]
[new commit from coworker] 
[my commit 2]
[my commit 1]

How can I rebase like that?

like image 368
atamanroman Avatar asked Sep 15 '25 01:09

atamanroman


1 Answers

Instead of git pull, do git pull --rebase.

(You can git reset --hard [my commit 3] to get back to where you were before the pull, then do git pull --rebase.)

like image 117
Amber Avatar answered Sep 17 '25 19:09

Amber