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?
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.
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.
Visit Gerrit then select Projects --> List --> SELECT-PROJECT --> Branches . Select the branch that interests you, click on gitweb located on the right-hand side.
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.
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
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
This feature was implemented very recently and will be available in Gerrit v2.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With