3

What I need to do: I have ten commits that are on master. I need to move those commits to a new branch. I have been periodically pulling, but I haven't pushed my work yet. How can I make my ten commits into a new branch that I can then push?

I've tried following the steps in this question here, but they don't work. Specifically, when I do the rebase, all I end up with is commits on master, none on my new branch. No commits are ever moved to the new branch, and I don't see how that would be possible given the steps provided in the question.

Community
  • 1
  • 1
mmr
  • 14,781
  • 29
  • 95
  • 145

3 Answers3

2

From my understanding, this is what you have:

* commit 10 (master)
|
* commit 9
|
...
|              * (origin/master)
* commit 1     |
|.------------^
*

I think what you are asking want is to have commits 1-10 on a new branch.

To do this, you simple label the branch with the branch name, then reset master to what origin/master has.

So:

git checkout master # your current latest set of changes (commit 10)
git branch feature # the name of your branch
git reset --hard origin/master # sets master to point to origin/master
git pull --rebase # updates master with origin/master
git checkout feature && git merge master # updates feature branch with what is on origin/master

This will end up with:

* commit 11 (feature) merge commit
|^------------.
* commit 10    |
|              ...
...
|              * (master, origin/master)
* commit 1     |
|.------------^
*

Is this what you would like to do?

Kaushik Shankar
  • 5,491
  • 4
  • 30
  • 36
  • This got me to the eventual solution, which was to: 1) checkout master 2) git log to get the most recent commit id 3) rebase 4) reset hard head 5) checkout the most recent commit (go to a detached head state) 6) create a new branch, and the commits are automatically placed into that new branch – mmr Jun 04 '13 at 18:38
0

One option is just pushing your work to a new branch:

git push HEAD:branchname

This will create a new branch branchname on the server, which contains you current work. - In this case it might get confusing, as your work is still on master on your local side.

To get this right you can just reset your local master to the remote version:

git reset --hard @{u}

Be aware that this will throw away all uncommitted chances.

To work then on branchname you can just do git checkout branchname.

michas
  • 25,361
  • 15
  • 76
  • 121
0

Just rename your branch and push it:

git branch -m branchname
git push -u branchname

Here -u is important to update the tracking branch.

michas
  • 25,361
  • 15
  • 76
  • 121