How do you push a Git tag to a branch using a refspec?

GitGit PushGit Tag

Git Problem Overview


I want to force push, for example, my tag 1.0.0 to my remote master branch.

I'm now doing the following:

git push production +1.0.0:master

I want to force the push, because all I care about is that the code inside the 1.0.0 tag is pushed to the master branch on the remote repository.

What am I doing wrong?

Update #1

When I SSH into my server where my Git repository is and execute git branch -l, I don't see the master branch listed either.

Update #2

After running git tag -l from inside the remote Git repository, I see that master is listed, meaning that when I ran the following:

git push production 1.0.0:master

It actually pushed the tag and created a tag named master rather than a new branch.

I want to basically push the contents of the tag 1.0.0 into the master branch of the remote Git repository.

Git Solutions


Solution 1 - Git

git push --tags production

Solution 2 - Git

It is probably failing because 1.0.0 is an annotated tag. Perhaps you saw the following error message:

> error: Trying to write non-commit object to branch refs/heads/master

Annotated tags have their own distinct type of object that points to the tagged commit object. Branches can not usefully point to tag objects, only commit objects. You need to “peel” the annotated tag back to commit object and push that instead.

git push production +1.0.0^{commit}:master
git push production +1.0.0~0:master          # shorthand

There is another syntax that would also work in this case, but it means something slightly different if the tag object points to something other than a commit (or a tag object that points to (a tag object that points to a …) a commit).

git push production +1.0.0^{}:master

These tag peeling syntaxes are described in git-rev-parse(1) under Specifying Revisions.

Solution 3 - Git

I create the tag like this and then I push it to GitHub:

git tag -a v1.1 -m "Version 1.1 is waiting for review"
git push --tags

Counting objects: 1, done.
Writing objects: 100% (1/1), 180 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To [email protected]:neoneye/triangle_draw.git
 * [new tag]         v1.1 -> v1.1

Solution 4 - Git

For pushing a single tag: git push <reponame> <tagname>

For instance, git push production 1.0.0. Tags are not bound to branches, they are bound to commits.

When you want to have the tag's content in the master branch, do that locally on your machine. I would assume that you continued developing in your local master branch. Then just a git push origin master should suffice.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael van RooijenView Question on Stackoverflow
Solution 1 - GitbstpierreView Answer on Stackoverflow
Solution 2 - GitChris JohnsenView Answer on Stackoverflow
Solution 3 - GitneoneyeView Answer on Stackoverflow
Solution 4 - GitkopporView Answer on Stackoverflow