threads / discuss / 24136

moving a remote branch?

Subject: moving a remote branch?

## tl;dr

8 messages between Jun 17, 2010 and Jun 17, 2010.

replies: 7people: 3as markdown or json

Thomas Anderson· Jun 17, 2010, 04:35 UTC · lore

git branch -m origin/zelnaga/featurea origin/zelnaga/featureb doesn't seem to be working for me. Instead, I get this error:l

error: refname refs/heads/origin/zelnaga/featurea fatal: Branch rename failed

Any ideas?
Nazri Ramliy· Jun 17, 2010, 06:19 UTC · re: Thomas Anderson · lore

Re: moving a remote branch?

On Thu, Jun 17, 2010 at 12:35 PM, Thomas Anderson <zelnaga@gmail.com> wrote:
Show 7 quoted lines
> git branch -m origin/zelnaga/featurea origin/zelnaga/featureb doesn't
> seem to be working for me.  Instead, I get this error:l
>
> error: refname refs/heads/origin/zelnaga/featurea
> fatal: Branch rename failed
>
> Any ideas?
The error  message could be improved here.

The reason you get the error is because you were asking git to rename a "remote" branch, which it refuses to do because, well, it's a remote branch, and for all practical purposes git won't allow you to modify any "remote" stuff as they are all read-only from our point of view.

If you run "git remote -v" you'll most likely see that "origin" is listed in the output which means that your "origin/zelnaga/featurea" is a remote branch because its name begin with "origin/".

Hope this helps.
nazri.
Peter Kjellerstedt· Jun 17, 2010, 08:28 UTC · re: Nazri Ramliy · lore

RE: moving a remote branch?

Show 33 quoted lines
> -----Original Message-----
> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On
> Behalf Of Nazri Ramliy
> Sent: den 17 juni 2010 08:20
> To: Thomas Anderson
> Cc: git@vger.kernel.org
> Subject: Re: moving a remote branch?
> 
> On Thu, Jun 17, 2010 at 12:35 PM, Thomas Anderson <zelnaga@gmail.com>
> wrote:
> > git branch -m origin/zelnaga/featurea origin/zelnaga/featureb doesn't
> > seem to be working for me.  Instead, I get this error:l
> >
> > error: refname refs/heads/origin/zelnaga/featurea
> > fatal: Branch rename failed
> >
> > Any ideas?
> 
> The error  message could be improved here.
> 
> The reason you get the error is because you were asking git
> to rename a "remote" branch, which it refuses to do because,
> well, it's a remote branch, and for all practical purposes git
> won't allow you to modify any "remote" stuff as they are all
> read-only from our point of view.
> 
> If you run "git remote -v" you'll most likely see that "origin"
> is listed in the output which means that your "origin/zelnaga/featurea"
> is a remote branch because its name begin with "origin/".
> 
> Hope this helps.
> 
> nazri.

Renaming a remote branch is a two step operation. First you push the old branch into its new name, and then you remove the old branch. It can be done with these commands:

	git push origin origin/featurea:refs/heads/featureb
	git push origin :featurea
//Peter
Nazri Ramliy· Jun 17, 2010, 12:13 UTC · re: Peter Kjellerstedt · lore

Re: moving a remote branch?

On Thu, Jun 17, 2010 at 4:28 PM, Peter Kjellerstedt > Renaming a remote branch is a two step operation. First you push the

Show 5 quoted lines
> old branch into its new name, and then you remove the old branch. It
> can be done with these commands:
>
>        git push origin origin/featurea:refs/heads/featureb
>        git push origin :featurea
I'd like to add (more confusion!:) with this clarification:

The two push operation above rename the branch on the remote side. It does not affect any of your local branches.

If you do "git branch -a" then you'd still see the "origin/zelnaga/featurea" branch.

Doing a "git fetch origin" will get the newly renamed branch from the remote repo and create a local version of it on your local repo.

At this point you can do "git branch -D origin/featurea".
nazri
Peter Kjellerstedt· Jun 17, 2010, 13:02 UTC · re: Nazri Ramliy · lore

RE: moving a remote branch?

Show 20 quoted lines
> -----Original Message-----
> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On
> Behalf Of Nazri Ramliy
> Sent: den 17 juni 2010 14:13
> To: Peter Kjellerstedt
> Cc: Thomas Anderson; git@vger.kernel.org
> Subject: Re: moving a remote branch?
> 
> On Thu, Jun 17, 2010 at 4:28 PM, Peter Kjellerstedt 
> > Renaming a remote branch is a two step operation. First you push the
> > old branch into its new name, and then you remove the old branch. It
> > can be done with these commands:
> >
> >        git push origin origin/featurea:refs/heads/featureb
> >        git push origin :featurea
> 
> I'd like to add (more confusion!:) with this clarification:
> 
> The two push operation above rename the branch on the remote side.
> It does not affect any of your local branches.

No, it does not affect any local branches, but it _does_ effect the representation of the remote branches in the local repository.

> If you do "git branch -a" then you'd still see the
> "origin/zelnaga/featurea" branch.
No, you will not (at least not with git 1.7.1 that I use). 

Neither do you need to do the two steps below as the two pushes above are enough to also keep the status of the remote branches in sync in the local repository..

Show 6 quoted lines
> Doing a "git fetch origin" will get the newly renamed branch from the
> remote repo and create a local version of it on your local repo.
> 
> At this point you can do "git branch -D origin/featurea".
> 
> nazri
//Peter
Nazri Ramliy· Jun 17, 2010, 13:19 UTC · re: Peter Kjellerstedt · lore

Re: moving a remote branch?

On Thu, Jun 17, 2010 at 9:02 PM, Peter Kjellerstedt >
Show 7 quoted lines
> No, you will not (at least not with git 1.7.1 that I use).
>
> Neither do you need to do the two steps below as the two pushes
> above are enough to also keep the status of the remote branches
> in sync in the local repository..
>
> //Peter
Ah, you are right. Thanks for the lesson.
nazri.
Thomas Anderson· Jun 17, 2010, 13:55 UTC · re: Peter Kjellerstedt · lore

Re: moving a remote branch?

Do I need to switch to the local featurea branch before doing "git push origin origin/featurea:refs/heads/featureb" or can I do that while in the default branch?

On Thu, Jun 17, 2010 at 3:28 AM, Peter Kjellerstedt <peter.kjellerstedt@axis.com> wrote:

Show 44 quoted lines
>> -----Original Message-----
>> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On
>> Behalf Of Nazri Ramliy
>> Sent: den 17 juni 2010 08:20
>> To: Thomas Anderson
>> Cc: git@vger.kernel.org
>> Subject: Re: moving a remote branch?
>>
>> On Thu, Jun 17, 2010 at 12:35 PM, Thomas Anderson <zelnaga@gmail.com>
>> wrote:
>> > git branch -m origin/zelnaga/featurea origin/zelnaga/featureb doesn't
>> > seem to be working for me.  Instead, I get this error:l
>> >
>> > error: refname refs/heads/origin/zelnaga/featurea
>> > fatal: Branch rename failed
>> >
>> > Any ideas?
>>
>> The error  message could be improved here.
>>
>> The reason you get the error is because you were asking git
>> to rename a "remote" branch, which it refuses to do because,
>> well, it's a remote branch, and for all practical purposes git
>> won't allow you to modify any "remote" stuff as they are all
>> read-only from our point of view.
>>
>> If you run "git remote -v" you'll most likely see that "origin"
>> is listed in the output which means that your "origin/zelnaga/featurea"
>> is a remote branch because its name begin with "origin/".
>>
>> Hope this helps.
>>
>> nazri.
>
> Renaming a remote branch is a two step operation. First you push the
> old branch into its new name, and then you remove the old branch. It
> can be done with these commands:
>
>        git push origin origin/featurea:refs/heads/featureb
>        git push origin :featurea
>
> //Peter
>
>
Peter Kjellerstedt· Jun 17, 2010, 15:05 UTC · re: Thomas Anderson · lore

RE: moving a remote branch?

Show 11 quoted lines
> -----Original Message-----
> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On
> Behalf Of Thomas Anderson
> Sent: den 17 juni 2010 15:56
> To: Peter Kjellerstedt
> Cc: Nazri Ramliy; git@vger.kernel.org
> Subject: Re: moving a remote branch?
> 
> Do I need to switch to the local featurea branch before doing "git
> push origin origin/featurea:refs/heads/featureb" or can I do that
> while in the default branch?

You do not need to switch branch. The command above has all the information it needs on the command line.

One thing to note though. If you have a local branch tracking the remote featurea branch, it will not automatically start tracking the featureb branch when you rename the remote branch. You will have to fix the tracking manually (either by setting up a new tracking branch for featureb, or by editing the .git/config file to reflect the new situation).

//Peter

← back to recent threads