Push git commits & tags simultaneously

Viewed 188566

I'm aware of the reason that git push --tags is a separate operation to plain old git push. Pushing tags should be a conscious choice since you don't want accidentally push one. That's fine. But is there a way to push both together? (Aside from git push && git push --tags.)

6 Answers

@since Git 2.4

git push --atomic origin <branch name> <tag>

Let's say you have created a new repo on github. So the first step would be to clone the repo:git clone {Your Repo URL}

You do your work, add some files, code etc., then push your changes with:

git add .
git commit -m "first commit"
git push

Now our changes are in main branch. Let's create a tag:

git tag v1.0.0                    # creates tag locally     
git push origin v1.0.0            # pushes tag to remote

If you want to delete the tag:

git tag --delete v1.0.0           # deletes tag locally    
git push --delete origin v1.0.0   # deletes remote tag

Just tested on git 2.31.0: git push <refspec> --tags. This has the advantage that it pushes ALL tags, not just annotated tags like --follow-tags.

Git GUI

Git GUI has a PUSH button - pardon the pun, and the dialog box it opens has a checkbox for tags.

I pushed a branch from the command line, without tags, and then tried again pushing the branch using the --follow-tags option descibed above. The option is described as following annotated tags. My tags were simple tags.

I'd fixed something, tagged the commit with the fix in, (so colleagues can cherry pick the fix,) then changed the software version number and tagged the release I created (so colleagues can clone that release).

Git returned saying everything was up-to-date. It did not send the tags! Perhaps because the tags weren't annotated. Perhaps because there was nothing new on the branch.

When I did a similar push with Git GUI, the tags were sent.

Tags sent with Git GUI

For the time being, I am going to be pushing my changes to my remotes with Git GUI and not with the command line and --follow-tags.

Tried everythig.

The only solution which worked for me to avoid triggering two CI builds for the same commit on Gitlab was this:

git push -o ci.skip && git push --tags

as suggeted by @user1160006 in a comment.

I repeat here as a proper answer to make it more visible to anyone interested. And as a reminder for me ;)

Related