On Tue, 13 Dec 2011, Curtis Olson wrote:

> Hey all,
>
> I have a quick question for the git experts among us.  I've done some
> googling, but I must not have my search query phrased exactly right, or
> maybe I don't quite know the right git terminology for what I want to do.
> Hopefully it's simple enough.
>
> I have a local project here that uses git and has a single master branch.
>
> I had a wild and crazy idea that I wanted to explore, but knew it would
> involve a lot of code refactoring and rearchitecting -- I didn't want to
> mess up my good working tree -- especially if the idea didn't work out.  So
> I created a branch:
>
> git checkout -b newidea
>
> I then pushed forward with the new idea inside this branch, made several
> rounds of changes and many commits to this new branch.  Now I really like
> my new idea and I want all this work moved back into my master branch.
>
> What's the best way do to this?
>
> Could I rename the master branch to be "pre-newidea" or whatever I want to
> call it, and then rename my "newidea" branch to "master"?  Or is that bad
> git practice?

If your newidea branch is nice and tidy and a straight continuation of 
your current master branch (i.e. they have not diverged) you can just 
merge the newidea branch into master (if they have not diverged it will 
just be a fast-forward of the master branch).

You can create a new branch to keep track of your old master point first 
if you like:

git branch old-master master

git branch -h  or --help will show many useful options to git branch 
e.g. for creating, renaming and deleting branches.

As long as you don't rewrite the history you can always create a new 
branch starting at any old commit so there is no particular need to 
create such branches before you need them (except maybe to help 
remembering where that point was).

If the branches have diverged I would consider cherry-pick over the 
commits from the newidea branch into master (if they are not very many) 
and perhaps also tidy them up with using interactive rebasing before 
publishing the new master state. This is particularily useful if master is 
a public branch that receives commits from other developers - it avoids 
the rather ugly multiple levels of merges we see in e.g. fgdata.
(See also git rebase).

gitk --all is a very useful tool to see where your different branches are 
in the history and how they relate to each other.

> Would it be better to merge all the change in my "newidea" branch back into
> master?  If so, how would I go about doing that?

While on the master branch:

git merge newidea


Cheers,

Anders
-- 
---------------------------------------------------------------------------
Anders Gidenstam
WWW: http://gitorious.org/anders-hangar
      http://www.gidenstam.org/FlightGear/

------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and 
improve service delivery. Take 5 minutes to use this Systems Optimization 
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to