13

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!

2 Answers 2

25

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.

3
  • Oh cool! That's pretty straightforward! Could I instead merge master into newfeature and then merge newfeature into tempfeature which will mean that my newfeature is up to date with the master as well? Commented Jan 8, 2013 at 10:48
  • Also presumably that will stop me having to merge master twice? Once now for tempfeature and again in the future with newfeature Commented Jan 8, 2013 at 10:50
  • 1
    1. Yes, of course. Branching works in all directions. 2. Yes. You could also use git-cherry-pick (git-scm.com/docs/git-cherry-pick) to apply changes of certain commits selectively.
    – Max Leske
    Commented Jan 8, 2013 at 11:46
4

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.

1
  • 2
    git stash what a great command, didn't know you could do that. I have been committing or resetting files all this time. :) Thanks for your answer. Commented Jan 8, 2013 at 10:49

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