threads / discuss / 22503

How to rebase and rename?

Subject: How to rebase and rename?

## tl;dr

2 messages between Feb 3, 2010 and Feb 3, 2010.

replies: 1people: 2as markdown or json

Peter Krefting· Feb 3, 2010, 09:05 UTC · lore
Hi!

If I have a repository with a topic branch that is published, and that I want to rebase and republish under a new name, is there an easy way of doing that?

I.e., I want to go from
      ---C---D topic-1
     /
  --A---X---X---B master
to
        ---C---D topic-1
 	  /
      /           ---C'---D' topic-2
     /           /
  --A---X---X---B master
Currently, I do something along the lines of:
  git branch topic-2 topic-1
  git rebase master topic-2

but that feels wrong as it creates the "topic-2" branch pointing the the wrong way first. Is there a way to eliminate that step?

-- 
\\// Peter - http://www.softwolves.pp.se/
Jeff King· Feb 3, 2010, 09:48 UTC · re: Peter Krefting · lore

Re: How to rebase and rename?

On Wed, Feb 03, 2010 at 10:05:10AM +0100, Peter Krefting wrote:
Show 11 quoted lines
> If I have a repository with a topic branch that is published, and
> that I want to rebase and republish under a new name, is there an
> easy way of doing that?
> [...]
> Currently, I do something along the lines of:
> 
>  git branch topic-2 topic-1
>  git rebase master topic-2
> 
> but that feels wrong as it creates the "topic-2" branch pointing the
> the wrong way first. Is there a way to eliminate that step?

No, I think that is the best way to do it. Since the creation of topic-2 is happening in your (presumably) private repo, it is not a big deal for it to exist in an unintertesting state for a few seconds.

If you really cared, you could do the work on a detached HEAD and then assign the result to a new branch, but that is even more typing:

  git checkout topic-1^0
  git rebase master
  git checkout -b topic-2

It also causes git to do slightly more work. In your example, the branch creation is O(1), then rebase resets back to master and applies each commit in topic-1 in turn. In mine, we actually reset the checkout to topic-1, then reset it to master, and then apply the commits. Not that it probably matters unless you have some enormous repository.

-Peff

← back to recent threads