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

Re: renaming remote branches

From
Jeff King <peff@peff.net>
Date
Apr 16, 2009, 06:59 UTC
Message-ID
<20090416065934.GA20071@coredump.intra.peff.net>
In-Reply-To
<buo3ac9jn18.fsf@dhlpc061.dev.necel.com>
On Thu, Apr 16, 2009 at 12:27:31PM +0900, Miles Bader wrote:
Show 7 quoted lines
> I can "rename" a remote branch by doing:
> 
>    git push REMOTE REMOTE/OLD:refs/heads/NEW
>    git push REMOTE :OLD
> 
> is there any better way to do this (I mean, er... more
> user-friendly/less-dangerous/... I dunno... "better" :-)?

No, the git protocol doesn't know about moving refs at all, so you are stuck with creation and deletion (and the creation, as you noticed, is even more painful because we don't guess that "NEW" is going to be a branch, so you are stuck saying "refs/heads/").

Not only is this not user-friendly, but it does not preserve any branch config or reflog at the remote (both things that "branch -m" does).

In your situation, I would probably do:
  ssh remote-host 'cd remote-dir && git branch -m OLD NEW'
but that is not always an option, depending on your setup.
> Also, I note that the old name ("OLD") remains in .git/info/refs, both
> locally and in the remote; is this a problem?  I can update the local
> .git/info/refs by running "git update-server-info", but I'm not sure how
> to do in for the remote repo without having a login there...

If you are not sharing your repo over a dumb transport (like http), then the contents of .git/info/refs shouldn't matter. If you are, then you should enable the post-update hook to run update-server-info after every push (i.e., it is not just the deletion that is a problem, but none of your pushes is being marked in .git/info/refs).

-Peff
Previous: Miles BaderNext: Miles Bader
Message 2 of 9 in “renaming remote branches”
  1. Miles BaderApr 16, 2009
  2. Jeff KingApr 16, 2009
  3. Miles BaderApr 16, 2009
  4. Jeff KingApr 16, 2009
  5. Jay SoffianApr 16, 2009
  6. Jeff KingApr 16, 2009
  7. Miles BaderApr 17, 2009
  8. Jeff KingApr 17, 2009
  9. Dmitry PotapovApr 17, 2009

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.