Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Gerrit is unable to create branch by itself?

Following this answer and my own question, I have a simple (hope so) question.

If I'm pushing a particular branch, with all required refs properly set:

git checkout 82-blah-blah
git push origin HEAD:refs/for/82-blah-blah

Why do I always get:

! [remote rejected] HEAD -> refs/for/82-blah-blah (branch 82-blah-blah not found)

and I always have to go to Gerrit's UI and create that branch manually?

Isn't that an obvious step, that Gerrit could simply automate? Or am I missing something?

like image 504
trejder Avatar asked Dec 16 '13 08:12

trejder


People also ask

How do I create a branch on Gerrit?

There are several ways to create a new branch in a project: in the Web UI under 'Projects' > 'List' > <project> > 'Branches' via the Create Branch REST endpoint. via the create-branch SSH command.

How do I initialize a new branch?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do I find my Gerrit branches?

Visit Gerrit then select Projects --> List --> SELECT-PROJECT --> Branches . Select the branch that interests you, click on gitweb located on the right-hand side.

How do I change my branch on Gerrit?

Go to the master branch locally and pull from Gerrit, which is usually an origin remote. Switch your local branch and use git rebase master . You will be able to resolve conflicts. When you are done use git add and after successful git rebase --continue end up with the commit on top of the current master branch.


3 Answers

The accepted answer is referring to a feature that allows users to create branching using SSH, all it adds is the CreateBranchCommand. The original issue request might actually refer to what @trejder wants but the implementation is just a create branch through an SSH command.

I was under the impression that if you have the create-reference right you can push to ref/for/new-branch but I was wrong, just tested it and it doesn't work. It only allows you to create new branches but directly pushing to them.

Guess the fastest way to get it done is:

git checkout master
git push origin HEAD:new-branch
git checkout new-branch
git push origin HEAD:/refs/for/new-branch
like image 104
uncletall Avatar answered Oct 18 '22 01:10

uncletall


Use this simple bash script to create and push a new branch to gerrit. Usage: Branch_name and CommitId are 2 inputs needed

#!/bin/bash 
read -p "Enter New Branch Name: " Branch_Name 

read -p "Enter CommitID:" CommitID 

git fetch --all 

git branch $Branch_Name $CommitID 

git push origin $Branch_Name:$Branch_Name 

git checkout $Branch_Name 

git branch --set-upstream-to=origin/$Branch_Name $Branch_Name
like image 33
kalaivani Avatar answered Oct 18 '22 02:10

kalaivani


This feature was implemented very recently and will be available in Gerrit v2.9.

like image 35
mvp Avatar answered Oct 18 '22 02:10

mvp