Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I merge master into a feature branch to bring it up to date? Would this be considered bad practice?

I have a situation like this:

            (master)
A - B - E - F
      \       
        C - D
            (feature-x)

Should I merge master into feature-x if I need critical fixes E and F into the feature-x branch to continue development and I intend to merge back into master?

Is there any disadvantage to repeated merging master into a feature branch and then the feature back into master when the feature branch might or might not be shared with other developers?

like image 457
Chaudhry Junaid Avatar asked Aug 12 '15 20:08

Chaudhry Junaid


People also ask

Is it OK to merge master into feature branch?

But whatever branch management strategy you use, developers aren't supposed to merge master into branches. In fact, the exact opposite is supposed to happen.

Should you merge master into feature branch or rebase?

If the feature branch you are getting changes from is shared with other developers, rebasing is not recommended, because the rebasing process will create inconsistent repositories. For individuals, rebasing makes a lot of sense. If you want to see the history completely same as it happened, you should use merge.

When should I merge to master branch?

Once the new feature is complete – i.e. a set of changes has been committed on the feature branch – it is ready to be merged back into the master branch (or other main code line branch depending on the workflow in use).

Should you merge master back into develop?

Once you merge develop to master then both are already in sync with each other so there is no need to merge again master into develop.


1 Answers

So far as I understand, merging master into your feature branch isn't considered bad practice. @larsks answer gives some good info about how to use rebasing which is an option. But be sure to follow the golden rule "Do not rebase commits that exist outside your repository"(see Perils of rebasing).

To clarify: 'commits that exist outside your repository' would be public (pushed) commits.

If you wonder whether rebasing, is better than merging or vise versa, I would suggest you look over: 'Rebase vs. Merge'. The article points out that the answer to this is dependent on what you and your team think is best for your project.

For larger projects, I like the history to show exactly what happened. So where I work, we usually merge master into our feature branches to get them up to date with the latest code. Though, I wouldn't necessarily consider this a global best practice for everyone. However, it's not considered bad practice either.

Some others like to have very clean history, so for them rebasing may be considered the better option.

like image 147
James Jacobson Avatar answered Sep 22 '22 21:09

James Jacobson