Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two branches to create new branch

We have a few branches...

  • master is our dev branch.
  • feature-newfeature is a new feature.
  • feature-tempfeature is a new feature that our product team have asked for until new feature is created. feature-newfeature was started a while ago and hasn't been merged into master yet (but there have been other changes to master).

We have now been instructed to put this temp feature in which needs all the changes from master - so its a releasable build - but also needs some of the stuff we've been working on in newfeature (as they say "you can reuse some of the stuff you've already done").

How would it be best to go about doing this? I have created feature-tempfeature from the master branch. feature-newfeature isn't finished, and I don't want to merge it into master.

I don't want to just use feature-newfeature either because we want to be able to keep working on that in parallel.

How would you sort out this issue in your dev environment?

Many thanks!

like image 319
Thomas Clayson Avatar asked Jan 08 '13 10:01

Thomas Clayson


2 Answers

branches are just aliases for a specific commit. Therefore you can have multiple branches that actually point to the same commit. So, what you could do is to create a new branch newBranch that points to the same commit as master and then merge feature-tempfeature into newBranch. The effect would be the same as merging into master, except that master stays untouched.

like image 186
Max Leske Avatar answered Oct 16 '22 07:10

Max Leske


From my understanding your scenario is:

---master----
\___tempf____
\___newf_____

Your problem: You need tempf with changes of master as well as newf so

Solution:

1) Stash your unsaved changes in tempf with $ git stash

2) Merge master with tempf and merge newf with tempf to have the changes of the both master and newf

3) Stash pop your changes with $ git stash pop

And as @MaxLeske said, branches are just aliases, they serve just like pointer to a commit but are not the commits themselves.

like image 29
uday Avatar answered Oct 16 '22 06:10

uday