17

I have a branch called v2.0 in gerrit. Now I want to the current stat of this branch as v2.0.1.

In my local repository I checked out the branch, then added the tag using

git tag v2.0.1

Now I'm trying to push that to gerrit, but I'm not sure how. I tried this:

$ git push origin v2.0.1 HEAD:refs/heads/v2.0
! [remote rejected] v2.0.1 -> v2.0 (prohibited by Gerrit)

How can I push the tag to gerrit?

Frank
  • 64,140
  • 93
  • 237
  • 324

4 Answers4

25

After some googling, I found the answer:

gerrit accepts only annotated tags. It's quite straightforward to create and push an annotated tag:

git checkout v2.0
git tag -am "Adding v2.0.1 tag" v2.0.1
git push origin v2.0.1 HEAD:refs/heads/v2.0
Frank
  • 64,140
  • 93
  • 237
  • 324
  • 5
    The above command works for me, I was just hoping that someone could explain the push. Why is the tag pushed to refs/heads/branchname and not refs/tags? – TheCycoONE Jun 13 '14 at 13:07
  • 5
    HEAD:refs/heads/v2.0 is unneeded. It is an additional refspec that pushes HEAD on the local repository to refs/heads/v2.0 on gerrit. The "v2.0.1" is what pushes the tag to gerrit, it is equivalent to refs/tags/v2.0.1:refs/tags/v2.0.1 – Woodi_333 Jun 07 '16 at 14:27
  • As stated in [this](https://stackoverflow.com/a/38194475/2285820) answer, Gerrit also supports leightweight tags using the `Create Reference` permission on `refs/tags/*` – ub_marco Dec 01 '20 at 09:37
13
  1. Add the permissions:

Click your project Access, add permissions as following:

Reference:  
refs/tags/*

Push Annotated Tag 
Push Signed Tag 
  1. Add your tags

Annotated tag: git tag -a "message" tag_name

Signed tag: git tag -s tag_name

  1. push your tags

simple cmd: git push --tags

If you want to fetch tags from your server repo using cmd:

git fetch --tags

You can check the doc:

https://review.typo3.org/Documentation/access-control.html#category_push_annotated https://review.typo3.org/Documentation/access-control.html#category_push_signed

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
lijinma
  • 2,914
  • 1
  • 23
  • 22
6

Tags and branches are completely independent concepts in Git, so your command doesn't make sense. A tag only links to a commit, and is repository-wide.

Both tags and branches are references, think about tags as fixed references to a commit, and branches as moving references on the tip of a commits' branch.

If the commit tagged v2.0.1 is already in the v2.0 branch I'd say you only have to push both to origin. If not, you'll want to merge the branch containing the tag into the v2.0 branch, and push both.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
1

If you push a lightweight tag, you should add the privilege 'Create Reference' for the reference name refs/tags/*, because as CharlesB said, both tags and branches are references.

After adding the 'Create Reference' right, you can use git push --tags to push lightweight tags.

charles
  • 11,212
  • 3
  • 31
  • 46
herbertD
  • 10,657
  • 13
  • 50
  • 77