Push git commits tags simultaneously
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When you run git push, Git sends branch references, not tags, unless you ask for them explicitly. If you want your commits and release tags to arrive on the remote together, the safest approach is usually --follow-tags, with --tags reserved for the rarer case where you truly want every local tag pushed.
What git push Sends by Default
A normal branch push updates the branch ref on the remote:
That command transfers any commits needed for main, but it does not automatically push tags that point to those commits. This surprises people during releases because the remote branch advances while the release tag remains local.
Recommended Option: --follow-tags
If you create annotated release tags, --follow-tags is the most practical one-command solution.
This does two useful things:
- It pushes the branch update for
main. - It also pushes annotated tags that are reachable from the commits being pushed.
That behavior is deliberate. It avoids flooding the remote with unrelated old tags while still covering the normal release workflow.
When to Use --tags
If you really need to push every local tag along with your branch update, use --tags:
Be careful with this form. It pushes all local tags, not just the one you created for the current release. In a repository with experimental or stale tags, that may be broader than you intended.
For a single specific tag, keep the push explicit:
That is two commands rather than one, but it is the clearest option when you want tight control.
Annotated vs Lightweight Tags
The difference matters because --follow-tags only follows annotated tags.
Annotated tag:
Lightweight tag:
If you use the lightweight form, git push origin main --follow-tags will not send that tag. For release management, annotated tags are usually the better choice anyway because they preserve the tagger, date, and message.
A Practical Release Flow
A clean release sequence might look like this:
Then confirm the remote state:
That extra verification step is useful in CI-heavy teams, where a missing tag can break packaging or deployment steps even though the branch push succeeded.
Pushing Multiple Branches with Tags
If you are pushing several refs at once, the same idea applies:
Git will update both refs and include matching annotated tags reachable from the pushed commits. This is often enough for coordinated release branches.
Common Pitfalls
- Assuming a normal branch push automatically carries release tags with it.
- Using lightweight tags and expecting
--follow-tagsto push them. - Reaching for
--tagsin a repository where many local tags should stay private or unpublished. - Skipping remote verification even though downstream automation depends on the tag existing.
- Treating tags like branch refs instead of separate refs with their own push behavior.
Summary
- '
git push origin mainpushes commits for the branch, not tags.' - '
git push origin main --follow-tagsis the usual one-command release workflow.' - '
--follow-tagsworks with annotated tags, not lightweight tags.' - '
git push origin main --tagspushes every local tag and should be used carefully.' - Verify remote heads and tags after a release push if the tag triggers downstream automation.
Related reading
- Push local Git repo to new remote including all branches and tags
- Pushing an existing Git repository to SVN
- Pushing empty commits to remote
- Pushing to Git returning Error Code 403 fatal HTTP request failed
- Putting Git hooks into a repository
- Python not working in the command line of git bash
- Quick Sort Vs Merge Sort
- RAFT term condition to commit an entry
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.