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

Re: How to rename remote branches if I only have "client access"?

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 20, 2016, 15:55 UTC
Message-ID
<xmqqr37bhv5k.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<nuamc4$uvk$1@blaine.gmane.org>
Manuel Reimer <Manuel.Spam@nurfuerspam.de> writes:
Show 10 quoted lines
> I have the following branches on my remote repo:
>
> new_version
> master
>
> I now want the "new_version" branch to be the "master" and the old
> "master" has to be renamed to the old version number (in my case
> 0.2.0).
>
> How to do this? 
I assume you have "git push" access into this remote repository.

You are correct that there is no way for you to tell "git push" (or any Git native method) to rename "master" to "maint-0.2.0".

What you can do is to push the commits at the tip of "master" and "new_version" to "maint-0.2.0" and "master" respectively, and then delete "new_version". If the 'master' and 'new_version' you locally have are already the 'master' and 'new_version' you have over there that you want to see sit at the tips of updated 'maint-0.2.0' and 'master' branches, then:

    git push $remote master:refs/heads/maint-0.2.0 new_version:master
    git push $remote :new_version
would do this.

Note that in the <source>:<dest> syntax in "git push", the <source> side refers to the names in your local repository; if your local 'master' is different from what you want to see at the tip of 'maint-0.2.0' at the remote after this, replace it with whatever name you give to that commit locally in the above example.

Also note that the this push may not succeed if your new_version is not a descendant of the current 'master' at the remote. You'd need to use +<source>:<dest> to force it if that is the case.

The second command that has an empty <source> is to delete <dest>.

Lastly, the remote side can be configured to forbid deletion of branches, and/or to forbid forced pushes. If your remote is configured that way (which is not default), then there is no way for you to do any of the above (and that is by design---the server operators use these configuration variables to forbid you from doing something, so you shouldn't be able to override that choice).

> Currently this causes me much trouble as I can't
> delete the remote "master" repository as this is the "remote current
> repository"...

Sorry, but you lost me here. You were talking about two branches in a single repository that is remote earlier. I do not know what this "remote master repository" you bring up in this paragraph is, and why you can't remove it. Not that I want to know the answers to these questions myself. I just do not understand these as a reason behind your wanting to rename branches at a remote repository.

Previous: Manuel Reimer
Message 2 of 2 in “How to rename remote branches if I only have "client access"?”
  1. Manuel ReimerOct 20, 2016
  2. Junio C HamanoOct 20, 2016

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.