Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a tag in remote repository without adding the repo on local

Tags:

git

Do have anyway to add a tag in remote repository without cloning/adding it on local. I just need to do it for marking QA builds

like image 304
Ahmad Avatar asked Sep 30 '13 10:09

Ahmad


People also ask

How do I add a tag to a git repository?

Create Git Tag. In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.

Which of the following commands can be used to push tags to a remote repository?

You can push all local tags by simply git push --tags command.

Does push send tags to remote repository?

Sharing TagsBy default, the git push command doesn't transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them.


1 Answers

You can create a remote tag having no local tags at all with

git push origin HEAD:refs/tags/foo

You can remove the same tag with

git push origin :refs/tags/foo

Here's an explanation.

Take the command git push. Without being too strict, the general syntax could be interpreted as

git push where what:onto

where is the name of the remote repository you want to push to.

what a reference (using one of the several kinds offered by git) to a commit of your local repository. It can be a SHA1, a branch name, a tag name or other.

onto in the name you want the remote will use to reference the thing you are pushing.

For example

git push origin master:master

is pushing to origin the commit (and all the other previous commits, if the remote does not have them) pointed by master, asking the remote repository to call it master, that is to save in its master branch the exact same SHA1 recorded in your local master branch (this is not exactly true, but accept this example to understand the principle).

Now, as a matter of facts, branches and tags are just ordinary files storing the SHA1 of a commit. You could see them as sort pointer variables, with a reference to some commit in the repository. Branches and tags are stored in .git/refs/heads and .git/refs/tags

Try with

cat .git/refs/heads/master

So, the previous could have been written

git push origin refs/heads/master:refs/heads/master

If you want to create a tag foo in the remote repository pointing to the same commit that is referenced by your master branch, you could run

git push origin master:refs/tags/foo

If you want to create a tag on the remote repository referencing exactly the same commit you are in at the moment, use the special branch HEAD, which is a pointer to your current position

For example, try with

git checkout master
cat .git/refs/heads/master
cat .git/HEAD

It should give twice the same value, confirming that master and HEAD reference the same commit, that is, you are on master

So, in order to create a remote tag referencing your local current commit use

git push origin HEAD:/refs/tags/a_tag_name

It is somehow like you are asking the remote origin to write in its file refs/tags/a_tag_name the value of the SHA1 contained in your local HEAD. This creates the tag in the remote repository.

If you push a null you will delete the tag

git push origin :/refs/tags/a_tag_name

That's all

like image 125
Arialdo Martini Avatar answered Oct 04 '22 15:10

Arialdo Martini