3

I have git repo in only one branch

A-B-C-D-E (master)

I want to split commits B, C and D to another branch called develop

A-E (master)
 \
  B-C-D (develop)

What is the easiest way to do this? No need to care about remote repo. Does cherry-pick just copy a commit to another branch? I think rebase is needed but I haven't used it before and I'd like to have this right on first try :)

There are some related questions but these do not have the last commit E to be taken care of.

1
  • If E is newer than D, you can not drow like you made. the commits must be ordered by creation time.
    – Kovge
    Commented Mar 17, 2013 at 12:29

2 Answers 2

3

This 2 commands should do the trick:

git branch develop D #create develop branch

git rebase --onto A D #make everything after D sit on top of A

Note that almost sure you will have some conflicts when running the rebase command. After fixing them, just run git add . and git rebase --continue.

2
  • First, rewinding head to replay your work on top of it... when trying to rebase. Which branch or commit should I be in?
    – Kuitsi
    Commented Mar 17, 2013 at 13:33
  • I've edited my post, please try now. You should be on master branch when doing the rebase.
    – niculare
    Commented Mar 17, 2013 at 13:44
0

I think that does not exactly possible, what you want. But the result of this is nearly same:

git checkout D  # checkout (step) to the D commit /this does not modify the master branch/
git branch develop  # create develop branch, based on D
git checkout develop # now you stand on D commit
git push origin develop # push the new branch to repo, named origin
git checkout master # now you stand on E commit again

This is the way to create your develop branch. Anyvaw a branch points to a commit. Or if you like this better, the branch is only an alias of a commit in the commit graph. For imagine we can think about a road in the commit graph, but actually it does not metter i think. ( the real edges of the commit graph creating when you commit (edge between the old and new commit) or you mergeing two commits (edge between the new commit, and the two 'parent' commit))

See the result:

git log --graph --decorate --pretty=oneline --abbrev-commit --all

   A-B-C-D-E (master)
         \-D (develop)

I hope could help you.

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