I can't push to a repository
When trying to push to a remote location from a local workstation.
Prerequisites
Before you get started, you should have:
an LFID account (sign up here)
git installed (see: http://www.git-scm.com/downloads)
git configured with your name, e-mail address and editor
git config --global user.name "Firstname Lastname" git config --global user.email "email@address.com" git config --global core.editor "text-editor-name"
Note: Your name and e-mail address (including capitalization) must match what you entered when creating your LFID account.
VIRTUALENV_PIP=23.2.1 pre-commit install-hooks
an ssh public/private key pair (see the good GitHub docs on generating ssh keys)register in the Gerrit server. See below for detailed instructions. Register your SSH key with Gerrit
- git-review version => 1.28 (see: https://www.mediawiki.org/wiki/Gerrit/git-review#Installation)
Note: The older version return the following error.
The "git review" command has been returning
remote: error: branch refs/publish/master:
remote: You need 'Create' rights to create new references.
remote: User: gvrangan
remote: Contact an administrator to fix the permissions
remote:
remote: Processing changes: refs: 1
remote: Processing changes: refs: 1, done
To ssh://git.opendaylight.org:29418/aaa.git
! [remote rejected] HEAD -> refs/publish/master (prohibited by Gerrit: not permitted: create)
error: failed to push some refs to 'ssh://gvrangan@git.opendaylight.org:29418/aaa.git'
Push patches to Gerrit
Open a shell to the directory containing the project repo
Create a local working branch, based on the branch you would like to make changes to.
git fetch origin git checkout -b new_feature_branch origin/production
Replace origin/production with whichever remote/branch you need to contribute to. Typically production or master is the latest development branch.
Make the modifications you would like to change in the project
Stage the modified files for commit. (Repeat for all files modified)
git add /path/to/file
Verify the staged files by running
git status
Commit the staged files by amending the patch
git commit -s
Note
The ‘-s’ argument signs the commit message with your name and email and is a statement that you agree to the Developer’s Certificate of Origin.
Push the patch to Gerrit using one of the 2 methods documented:
Push using git review
We recommend using git-review if possible as it makes working with Gerrit much easier.
Install
git-review
via your local package management systemIf your distro does not package git-review or you need a newer version.
Install it via PyPi in a virtualenv environment:
virtualenv ~/.virtualenvs/git-review pip install git-review
Push the patch to Gerrit
git review
We can optionally pass the parameter
-t my_topic
to set a topic in Gerrit. Useful when we have related patches to organize in one topic.
Once pushed we should see some output in the terminal as described in Gerrit Push Output.
Push using git push
This method is a useful fallback in situations where we cannot use git-review.
Use the following command:
git push <remote> HEAD:refs/for/master
Where <remote> is the Gerrit location to push the patch to. Typically ‘origin’ but can also be ‘gerrit’ depending on how we have our local repo setup.
Note
Notice the word “for” is explicitly intending to perform the push into Gerrit. Using “heads” instead, will attempt to make the a push into the repository bypassing Gerrit which can come in handy for some isolated cases (when having force push rights). Another variable commonly used is “refs/changes/<gerrit-number>” which is an explicit way of making an update to an existing gerrit. In such case, is best to let gerrit handle this via Change-Id in the commit text.
More options for this command: git-push.
Once pushed we should see some output in the terminal as described in Gerrit Push Output.
Push output
After pushing a commit to Gerrit we should see the following output:
(releng) cjac@probook0:/usr/src/git/lf/gerrit.linuxfoundation.org/releng/docs$ git review remote: Processing changes: updated: 1, refs: 1, done remote: remote: Updated Changes: remote: https://gerrit.linuxfoundation.org/infra/7404 documentation on the topic of git-review remote: To ssh://gerrit.linuxfoundation.org:29418/releng/docs.git * [new branch] HEAD -> refs/publish/master/git-review-docs
This output includes a URL to the patch. The number at the end is the patch’s change number.
Commit fails on gitlint-core error
If you get an error when running git commit like "ERROR: Could not find a version that satisfies the requirement gitlint-core==0.1.dev1+gacc9d9d (from gitlint)" try running the following commands and trying again.
pre-commit clean
VIRTUALENV_PIP=23.2.1 pre-commit install-hooks
For Further Information go to following URL's for Git Guide and Gerrit Guide.
Git Guide: https://docs.releng.linuxfoundation.org/en/latest/gerrit.html
Gerrit Guide: https://docs.releng.linuxfoundation.org/en/latest/gerrit.html
Related articles