user2316341
user2316341

Reputation: 375

Git - Merge vs rebase

I have had a look at When do you use git rebase instead of git merge? .

But I'd like to be sure about which solution to choose in this case:

I want to implement a new feature on master so I branch it to a new Feature branch.
I do 10 commits on Feature while someone else does other commits on Master.

My question is if I want to keep my branch apart from Master for testing purposes, but I need to test it with the new Master commits integrated. So, should I merge Master into Feature (and not Feature into Master which would apply my modifications on master before my testing) or do a rebase?

Upvotes: 13

Views: 12813

Answers (4)

Mahmoud Zalt
Mahmoud Zalt

Reputation: 31090

When 2 developers commit to the same repo (this will make a conflict) you can merge the 2 commits by creating a merge commit or you can rebase 1 of the commits (yours) on top of the other commit. it’s always better to rebase instead of generating a merge commit.

Upvotes: 0

Chuck L
Chuck L

Reputation: 51

In workflows I'm familiar with, there is a trunk, and integration branch(s), and feature branches

I have been rebaseing towards the 'derivative' branches. (by derivative branches, I mean the direction AWAY from the trunk), and merging towards the integration branches.

I like that I'm always working in a branch that has the same history as the branch I'll be integrating with. I like that the merge becomes a fast-forward, so, I know that what I just merged is exactly the same as what I just tested in my branch.

Upvotes: 5

VonC
VonC

Reputation: 1323065

Unless you have already pushed your branch (and you know others have cloned your repo), I would still do a rebase, as I mentioned in my own answer of "git rebase vs git merge".

Test or not, I usually do a rebase each time I update my local repo (git fetch), in order to ensure the final merge (Feature to master) will be a fast-forward one.

So it isn't just about how your history look, but it is mainly about making sure what you are developing isn't based on an old version of master, and keep working against the latest evolutions done in master over time.

Upvotes: 5

Mark Longair
Mark Longair

Reputation: 467033

Why not create a new branch to test the merged version? For example:

git checkout -b test-merged-feature master
git merge my-feature
[... do your testing ..]

There's no particularly reason to do a rebase here, but if you haven't already pushed your feature branch, that'd be fine as well. These questions are partly about how you would want your history to look - some people don't like seeing lots of merges; some prefer it as a way of keeping track of which commits contributed to a particular feature.

Upvotes: 5

Related Questions