daniel kullmann
daniel kullmann

Reputation: 14023

Merging two branches into one another

When doing a normal merge, you always merge one branch into another. The branch that is merged into changes, while the branch being merged from does not change.

Now, when I have a long-lived feature branch, I sometimes want to merge feature into master, but at the same time get all changes that have happened in master in the meantime into feature as well.

I could do two separate merges, but that feels messy. Is there a standard way to achieve what I want? Maybe just having the feature branch point to the merge commit by changing what that branch is pointing to? I'd like to know for both git and mercurial

Upvotes: 4

Views: 1566

Answers (2)

max630
max630

Reputation: 9238

After feature branch is merged into master, there is no point to continue it any more, because all commits from both master and feature branch are in master. Just start another feature branch from the merge commit.

The only case when the feature branch continues after merging to master (from the last commit before merging) is when you do not want changes from master.

Upvotes: 1

manojlds
manojlds

Reputation: 301147

You can consider rebasing your feature branch against master. Something like below:

git fetch origin master
git rebase origin/master

What happens is that your feature branch is rewritten to be based on the lastest master, and not the master that you started it off with.

Upvotes: 1

Related Questions