Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to merge upstream changes without causing a merge commit?

I have (commits were created in alphabetical order)

origin/topic  A-B-C-D-W-X

topic         A-B-C-D-Y-Z

Is there a way i can get my topic branch to look like

A-B-C-D-W-X-Y-Z

without introducing a merge commit?


Ordinarily I'd just do

$ git checkout topic
$ git fetch origin
$ git merge --ff-only origin/topic

But since Y and Z were committed after W and X, a fast forward will not work.

I suspect some clever rebasing or cherry picking might work but I can't wrap my head around it :{

like image 527
Mulan Avatar asked Nov 26 '13 16:11

Mulan


People also ask

How do you merge without a merge commit?

When you select the Rebase and merge option on a pull request on GitHub.com, all commits from the topic branch (or head branch) are added onto the base branch individually without a merge commit. In that way, the rebase and merge behavior resembles a fast-forward merge by maintaining a linear project history.

Does a fast forward merge create a commit?

Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit. Thus, if you want to ensure your branch is not changed or updated by the merge command, use --no-ff with --no-commit.

Does git merge always create commit?

In these scenarios, git merge takes two commit pointers, usually the branch tips, and will find a common base commit between them. Once Git finds a common base commit it will create a new "merge commit" that combines the changes of each queued merge commit sequence.


1 Answers

You can try with:

git checkout topic
git pull --rebase origin topic

Check the fetch man page notes about the rebase option.

I would recommend using something like git-smart, which will do a fast forward (which is faster) when possible, and if not, then a rebase. It will also stash local changes if you have any and give you a summary of the remote changes that were pulled.

like image 117
mamapitufo Avatar answered Sep 20 '22 10:09

mamapitufo