git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Correcting forgetting to make a new branch

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Mar 11, 2011, 15:49 UTC
Message-ID
<4D7A4483.5080209@drmicha.warpmail.net>
In-Reply-To
<AANLkTi=fp=-pwi7Mj9TptP22mtP51bzq5UwTLRx9LnNB@mail.gmail.com>
Howard Miller venit, vidit, dixit 11.03.2011 16:31:
Show 6 quoted lines
> The scenario is that I have done work on a branch and made a number of
> commits. What I wanted to do was to start a new branch before I made
> these commits. Unfortunatel, I got distracted and forgot that I hadn't
> done it.
> 
> Is there are neat way to create the branch and 'move' the commits over?

It depends on which commit you wanted the new branch to start with. If you have

...-*-*-*-X-*-*-*-*-A

on branch A and X is the commit where you meant to create a new branch B starting at X you can simply

git checkout A git branch B git reset --hard X

or simply

git branch -m A B git branch -f A X

If, on the other hand, you wanted to start B from a different commit Y, you will need to rebase:

git branch B A git branch -f A X git rebase --onto Y A B

After backing up, of course ;)
Michael
Previous: Howard Miller
Message 5 of 5 in “Correcting forgetting to make a new branch”
  1. Howard MillerMar 11, 2011
  2. Alexey FeldgendlerMar 11, 2011
  3. Matthieu MoyMar 11, 2011
  4. Howard MillerMar 11, 2011
  5. Michael J GruberMar 11, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.