Nicolas Raoul
Nicolas Raoul

Reputation: 60213

"git push" and "git push --tags" in the same command?

I usually run:

git push
git tag v4.7
git push --tags

Both the first and third operations connect to the server, which wastes time.
I want to make it faster by pushing only once. What command(s) would achieve this?
It is in a bash script, and needs to run fine in any branch, not just master.

Reading the manual, I don't think git push all is the solution:

--all: Instead of naming each ref to push, specifies that all refs under refs/heads/ be pushed.

--tags: All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

Upvotes: 34

Views: 32401

Answers (4)

Patrik Lindström
Patrik Lindström

Reputation: 1147

Since Git 2.4, you can use the following command to push tags and commits at the same time:

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

The following command push the commits to origin master branch together with tag reference tag-name: v4.7 .

git tag v4.7 -a -m "This the best atomic version ever"
git push --atomic origin master tag-name

See eg Push git commits & tags simultaneously SSO , Git - Push Tags and Commits Atomically , git-push docs

Upvotes: 1

Volen
Volen

Reputation: 357

You can create alias to have a fast access to this command:

git config --global alias.p '!git push && git push --tags'

or

git config --global alias.pa '!git push --all && git push --tags'

now you can do it like this:

git tag v4.7
git p

You can read more about aliases here

Upvotes: 4

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

According to the documentation of --tags you can specify additional refspecs to be pushed.

So you can simply use

git push --tags origin HEAD

Upvotes: 7

Kornel
Kornel

Reputation: 100200

The closest option may be:

git push --follow-tags

Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at committish that are reachable from the refs being pushed.

Upvotes: 38

Related Questions