views:

86

answers:

3

Hi,

I am trying to accomplish something that is probably very simple, though I cannot figure out how, or what I'm doing wrong. So to get straight to the point:

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

What I'm doing now is the following:

git push production +1.0.0:master

Yes, 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 location.

If anyone knows what I'm doing wrong, and/or has any suggestions/pointers, it'd appreciate it!

Thanks!

UPDATE
When I SSH into my server into 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 on 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. What I want to accomplish is to basically push the contents of tag 1.0.0 into the master branch of the remote git repository.

A: 

You need to specify the --force flag to force push.

vcsjones
Actually the __+__ before the __1.0.0__ is the equivalent of __--force__ or __-f__.
Michael van Rooijen
A: 

git push --tags production

bstpierre
+4  A: 

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.

Chris Johnsen
This solved the problem! However the __master__ branch needs to exist already. This isn't an issue on my end however. Thanks a lot for your help!
Michael van Rooijen
@Michael: Ahh. Yes, if *master* does not exist (as a branch or a tag), then `git push rep +tag:master` will create a tag named *master* instead of a branch. `git push rep +tag~0:master` (again, when *master* does not exist as a branch or a tag) will fail with “error: unable to push to unqualified destination”. The command that would have done what you wanted (before any *master* branch/tag existed) is `git push rep +tag~0:refs/heads/master` (`refs/heads/` is the namespace under which branches are stored).
Chris Johnsen
GREAT! That will help me out amazingly well. Very convenient! Thanks a lot for posting that information as well.
Michael van Rooijen