13

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?

3
  • That's up for a debate. I'd do a rebase.
    – 1615903
    Commented May 2, 2013 at 10:45
  • The top answer in the link you looked at provides a clear recommendation to rebase in your use case.
    – mah
    Commented May 2, 2013 at 10:47
  • In the future, please use more descriptive titles that more clearly explain what the problem is that you're trying to solve.
    – user456814
    Commented Jul 31, 2014 at 19:09

4 Answers 4

5

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.

3
  • I suppose having a "dev" branch to test the features together and then putting it on master for production would be a good practice in that case ? So the merge vs rebase question is simply about how you want your commits history to be ? Commented May 2, 2013 at 11:30
  • I agree on this option (merge in a new branch), so +1. But I still advocate for a rebase in my answer below.
    – VonC
    Commented May 2, 2013 at 11:31
  • @user2316341 a "dev" branch makes sense if you have to integrate (merge) several Feature branches, to see if they all work together. But if you have only one Feature branch at a time... it adds complexity for little gain.
    – VonC
    Commented May 2, 2013 at 11:34
5

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.

3
  • So you say that I should always do rebase most of the time, but not if I have already pushed my branch. Why is that ? What is the problem of having already pushed the branch ? Commented May 2, 2013 at 11:54
  • @user2316341 a rebase rewrite the history of SHA1. You would have to git push --force in that case to replace the history already pushed by the new one generated by the rebase. If noone is using your branch, this isn't a big deal, and rebase is by far the simplest and safest solution, over adding artificially a merge to an intermediate branch.
    – VonC
    Commented May 2, 2013 at 11:56
  • @user2316341 see stackoverflow.com/a/8940299/6309 as an example of the problem.
    – VonC
    Commented May 2, 2013 at 11:57
5

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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.