Creating 'remote' branch for existing repo in gerrit

Hi, I generally work in “master” branch for a repo. However for a new feature, I need to create a “separate feature branch” in gerrit (different from master branch).can you please share the “git commands” to create a “remote” branch from my local environment for the existing repo. Thank you.

Hi @debu3645

If the remote repository already exists and is linked to your local as the origin (i.e. you can git pull and git push Then all you have to do is to create the new branch locally. When you push that branch, it will be created on the remote.

If your new branch is to be called gerrit then

git checkout -b gerrit

Branch is created locally, and you are now “in” that branch.
Make changes, then

git push

gerrit will now appear in remote.

https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

1 Like

Thanks for the support @Alistair_KodeKloud
Had to execute the following commands in order to create a remote branch and push the codes into them.

git pull origin master
git checkout -b featlocinfo origin/master
git pull --rebase
vi neoamf.java 
git add .
git commit
git push -uf origin HEAD:refs/heads/origin/featlocinfo
git commit --amend
git push origin HEAD:refs/for/featlocinfo