Why Gerrit is unable to create branch by itself?

纵然是瞬间 提交于 2019-12-12 10:33:03

问题


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?


回答1:


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




回答2:


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



回答3:


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




回答4:


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!



来源:https://stackoverflow.com/questions/20606359/why-gerrit-is-unable-to-create-branch-by-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!