# moving a remote branch?

8 messages from 2010-06-17 to 2010-06-17. Participants: Thomas Anderson, Nazri Ramliy, Peter Kjellerstedt.
Thread: https://gitlist.dev/t/24136

## Thomas Anderson, 2010-06-17 04:35

Subject: moving a remote branch?
Message-ID: <AANLkTikA5jGl1LiU2sNTN1NP_syTfPAeLF7sS6dBozyN@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikA5jGl1LiU2sNTN1NP_syTfPAeLF7sS6dBozyN%40mail.gmail.com

```
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, 2010-06-17 06:19

Subject: Re: moving a remote branch?
Message-ID: <AANLkTimTSU7Db7cMlC0ZxQ47IoBUr4Ee4G-GfgDoYLmK@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimTSU7Db7cMlC0ZxQ47IoBUr4Ee4G-GfgDoYLmK%40mail.gmail.com
In-Reply-To: <AANLkTikA5jGl1LiU2sNTN1NP_syTfPAeLF7sS6dBozyN@mail.gmail.com>

```
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.

```

## Peter Kjellerstedt, 2010-06-17 08:28

Subject: RE: moving a remote branch?
Message-ID: <A612847CFE53224C91B23E3A5B48BAC74483CEEA82@xmail3.se.axis.com>
URL: https://gitlist.dev/e/A612847CFE53224C91B23E3A5B48BAC74483CEEA82%40xmail3.se.axis.com
In-Reply-To: <AANLkTimTSU7Db7cMlC0ZxQ47IoBUr4Ee4G-GfgDoYLmK@mail.gmail.com>

```
> -----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, 2010-06-17 12:13

Subject: Re: moving a remote branch?
Message-ID: <AANLkTikeLpvGA-RFBdMGblOnhNKJ6dUrpUZQlENMP51A@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikeLpvGA-RFBdMGblOnhNKJ6dUrpUZQlENMP51A%40mail.gmail.com
In-Reply-To: <A612847CFE53224C91B23E3A5B48BAC74483CEEA82@xmail3.se.axis.com>

```
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.

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, 2010-06-17 13:02

Subject: RE: moving a remote branch?
Message-ID: <A612847CFE53224C91B23E3A5B48BAC74483CEEB16@xmail3.se.axis.com>
URL: https://gitlist.dev/e/A612847CFE53224C91B23E3A5B48BAC74483CEEB16%40xmail3.se.axis.com
In-Reply-To: <AANLkTikeLpvGA-RFBdMGblOnhNKJ6dUrpUZQlENMP51A@mail.gmail.com>

```
> -----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..

> 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, 2010-06-17 13:19

Subject: Re: moving a remote branch?
Message-ID: <AANLkTileL-N2Q-90jcxKtQMkaPZob-slGevcorpBHXaj@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTileL-N2Q-90jcxKtQMkaPZob-slGevcorpBHXaj%40mail.gmail.com
In-Reply-To: <A612847CFE53224C91B23E3A5B48BAC74483CEEB16@xmail3.se.axis.com>

```
On Thu, Jun 17, 2010 at 9:02 PM, Peter Kjellerstedt >
> 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, 2010-06-17 13:55

Subject: Re: moving a remote branch?
Message-ID: <AANLkTikbOLRc6BvXtO8vznFevj0V_iZr34U1QaHCfFBh@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikbOLRc6BvXtO8vznFevj0V_iZr34U1QaHCfFBh%40mail.gmail.com
In-Reply-To: <A612847CFE53224C91B23E3A5B48BAC74483CEEA82@xmail3.se.axis.com>

```
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:
>> -----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, 2010-06-17 15:05

Subject: RE: moving a remote branch?
Message-ID: <A612847CFE53224C91B23E3A5B48BAC74483CEEB6D@xmail3.se.axis.com>
URL: https://gitlist.dev/e/A612847CFE53224C91B23E3A5B48BAC74483CEEB6D%40xmail3.se.axis.com
In-Reply-To: <AANLkTikbOLRc6BvXtO8vznFevj0V_iZr34U1QaHCfFBh@mail.gmail.com>

```
> -----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

```
