git: How to move last N commits made to master, into own branch?

Posted by amn on Stack Overflow See other posts from Stack Overflow or by amn
Published on 2010-12-30T13:30:45Z Indexed on 2010/12/30 13:54 UTC
Read the original article Hit count: 191

Filed under:
|

Hi all,

I have a repository where I had been working on master branch having last committed some 10 or so commits which I now wish were in another branch, as they describe work that I now consider experimental (i am still learning good git practices). Basically I would like to have these last 10 commits starting from a point in master to form another branch instead, so that I can have my master in a release state (which is what I strive for.)

So, this is what I have (rightmost X is the last commit good for release):

        b--b (feature B)
       /       
X--X--X--Z--Z--Z--Z--Z--Z (master)
    \
     a--a--a (feature A)

You can see that both X and Z are on master, while I want commits marked by Z (my feature Z work) to lie on their own feature branch, and so that rightmost X is at the tip of master forming a good master branch tip. I guess this is what I want:

        b--b (feature B)
       /       
X--X--X (master)
    \  \
     \  Z--Z--Z--Z--Z--Z (feature Z - the branch I want Z on)
      a--a--a (feature A)

That way I will have my master always ready for release, and merge A, B and Z features when the time comes.

Hope I am making sense here...

© Stack Overflow or respective owner

Related posts about git

Related posts about branching-and-merging