217

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.

7
  • Can you clarify what "not working" means? Does Git give an specific error, or does it have a null effect? Commented Oct 31, 2010 at 1:51
  • I'm sorry. Yes, so basically when I SSH into my server, into the git repository, and run git branch -l to list the branches, I only see my other branch. However, the git push production +1.0.0:master did push, an when I re-push it says Everything up-to-date, but I don't see the master branch on the remote server. Commented Oct 31, 2010 at 1:55
  • 5
    You should change the accepted answer. The second answer is much simpler than the one which is marked as accepted. Commented Sep 14, 2012 at 15:55
  • Sorry for the late response. I agree and have now changed the accepted answer. Commented Dec 22, 2012 at 12:27
  • 1
    @MichaelvanRooijen I don't understand how the accepted answer that you chose actually solves this problem. It doesn't overwrite a branch with a tag, it just pushes your tags to the remote. Commented Apr 27, 2014 at 20:08

4 Answers 4

469
git push --tags production 
Sign up to request clarification or add additional context in comments.

6 Comments

If the tag already exists on the remote you will need to delete the remote tag first with git push production :1.0.0.
If by any occasion you'll have branch with same name: '1.0.0' this push will fail so better use: git push production :refs/tags/1.0.0 to delete tag only
@Nerian: I think it just pushes tags
How does this actually solve the original poster's problem about overwriting a branch with a tag by force-pushing it? This just pushes all of your tags to a remote, it won't overwrite any branches.
Isn't the question asking how to push one tag? This command does a whole lot more than that.
|
65

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.

8 Comments

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: 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).
GREAT! That will help me out amazingly well. Very convenient! Thanks a lot for posting that information as well.
@brad: The ~{commit} syntax is literal (i.e. always those nine characters); the word commit is not a placeholder here.
ah ok! sorry, I was thinking you meant to put in the particular commit, makes more sense now.
|
61

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 

2 Comments

it push all your tags
Note that this won't actually solve the original poster's problem about overwriting a branch with a tag, it will just push your tags to a remote, without affecting branches.
10

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.

1 Comment

Note that this won't actually solve the original poster's problem about overwriting a branch with a tag, it will just push your tags to a remote, without affecting branches.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.