trejder
trejder

Reputation: 17505

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?

Upvotes: 11

Views: 23103

Answers (4)

kalaivani
kalaivani

Reputation: 604

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

Upvotes: 1

panayot_kulchev_bg
panayot_kulchev_bg

Reputation: 796

Let say new branch is "myNewBranch"

git checkout master
git push origin HEAD:myNewBranch

After commit some changes to push the new commit:

git push origin myNewBranch

Works for me. But..

Do not know why can not push the same commit to master after that and the other way around - if I have opened PR for review in master, can not push the same commit to the "myNewBranch". To do it had to abandon the PR to master and then cherry-pick the commit to the new local branch and then push to the remote "myNewBranch"

Good luck!

Upvotes: 0

uncletall
uncletall

Reputation: 6842

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

Upvotes: 25

mvp
mvp

Reputation: 116197

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

Upvotes: 3

Related Questions