Renaming branches in Gerrit

2,193 views
Skip to first unread message

SamT

unread,
Oct 30, 2013, 9:17:34 PM10/30/13
to repo-d...@googlegroups.com
Is there any way to rename a Git branch in a repository managed by Gerrit? The only options available for branch management in Gerrit as of version 2.3 are "Delete" and "Create Branch".

I thought of two options and both of which are possibly doable but a bit cumbersome:
1) I could create a new branch from the tip of an existing branch using Gerrit but I think the old branch must still exist and can not be removed. So, the old branch name will still stay there in the repository.

2) I have to go to the central repository and rename the branch using Git itself but I must also create the new branch and recreate all the access controls for this new branch name in Gerrit as well.

   Thanks,
    SamT

Shawn Pearce

unread,
Oct 31, 2013, 2:58:07 AM10/31/13
to SamT, repo-discuss
On Wed, Oct 30, 2013 at 6:17 PM, SamT <sam...@gmail.com> wrote:
> Is there any way to rename a Git branch in a repository managed by Gerrit?
> The only options available for branch management in Gerrit as of version 2.3
> are "Delete" and "Create Branch".

Correct, you can only do a rename by create new name, delete old name.

> I thought of two options and both of which are possibly doable but a bit
> cumbersome:
> 1) I could create a new branch from the tip of an existing branch using
> Gerrit but I think the old branch must still exist and can not be removed.
> So, the old branch name will still stay there in the repository.

After you create the new name you can delete the old name.

> 2) I have to go to the central repository and rename the branch using Git
> itself but I must also create the new branch and recreate all the access
> controls for this new branch name in Gerrit as well.

Yes, unfortunately you need to go edit access controls by hand.

SamT

unread,
Oct 31, 2013, 5:43:26 PM10/31/13
to repo-d...@googlegroups.com, SamT
Thanks Shawn for the reply. I will try one of the two options.

    Regards,
    SamT

FuRoSh1

unread,
Apr 16, 2014, 6:18:29 PM4/16/14
to repo-d...@googlegroups.com, SamT, Shawn Pearce
Hi Shawn,
I ran into a similar issue today. A user requested I create new project in gerrit. I used gerrit create-project as well they specified the branch name to use. However, they said the branch name is incorrect.
When viewing git repo in gerrit UI, the default branch name does not have any option (checkbox) to delete.

I can create a new branch I suppose, but is there a way to change this "default" un-checkable branch name by either:
1. Deleting it?
2. Renaming it?


On Wednesday, October 30, 2013 11:58:07 PM UTC-7, Shawn Pearce wrote:

Edwin Kempin

unread,
Apr 17, 2014, 2:22:13 AM4/17/14
to FuRoSh1, Repo and Gerrit Discussion, SamT, Shawn Pearce
2014-04-17 0:18 GMT+02:00 FuRoSh1 <fur...@gmail.com>:
Hi Shawn,
I ran into a similar issue today. A user requested I create new project in gerrit. I used gerrit create-project as well they specified the branch name to use. However, they said the branch name is incorrect.
When viewing git repo in gerrit UI, the default branch name does not have any option (checkbox) to delete.

I can create a new branch I suppose, but is there a way to change this "default" un-checkable branch name by either:
1. Deleting it?
2. Renaming it?
The "default" branch is not deletable because HEAD points to it.
To make the branch deletable change HEAD so that it points to another branch. In 2.9 you can do this from the WebUI, in earlier Gerrit versions you need to do this directly in the repository on the server.
 

On Wednesday, October 30, 2013 11:58:07 PM UTC-7, Shawn Pearce wrote:
On Wed, Oct 30, 2013 at 6:17 PM, SamT <sam...@gmail.com> wrote:
> Is there any way to rename a Git branch in a repository managed by Gerrit?
> The only options available for branch management in Gerrit as of version 2.3
> are "Delete" and "Create Branch".

Correct, you can only do a rename by create new name, delete old name.

> I thought of two options and both of which are possibly doable but a bit
> cumbersome:
> 1) I could create a new branch from the tip of an existing branch using
> Gerrit but I think the old branch must still exist and can not be removed.
> So, the old branch name will still stay there in the repository.

After you create the new name you can delete the old name.

> 2) I have to go to the central repository and rename the branch using Git
> itself but I must also create the new branch and recreate all the access
> controls for this new branch name in Gerrit as well.

Yes, unfortunately you need to go edit access controls by hand.

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

FuRoSh1 .

unread,
Apr 17, 2014, 3:08:24 PM4/17/14
to Edwin Kempin, Repo and Gerrit Discussion, SamT, Shawn Pearce
Thanks Edwin!!! 
I was able to change the default branch in Gerrit with your response. Tested this on a test environment 2.7 and ran on prod env 2.5.
cd /gerrit-path/data/git/repo.git
git symbolic-ref HEAD refs/heads/newBranch
Check gerrit UI and old default branch had checkbox that I could delete!!!
Easy peasy!
Reply all
Reply to author
Forward
0 new messages