Skip to content
Latchkey

git push Command: Publish Refs in CI

git push sends local commits, branches, and tags to a remote repository.

When CI commits version bumps, changelogs, or tags, it pushes them back. The flag choices determine whether tags travel along and how safely force-pushes behave.

Common flags

  • --tags - push all local tags in addition to the current branch
  • --follow-tags - push annotated tags that are reachable from the pushed commits
  • --force-with-lease - force-push only if the remote ref has not moved since you fetched it
  • --set-upstream / -u - set the upstream tracking ref while pushing
  • --atomic - make the push all-or-nothing across multiple refs
  • --delete <ref> - delete a ref on the remote

Example

shell
# Push a release commit and its annotated tag together
git push --follow-tags origin HEAD:main
# Safely update a bot branch without clobbering others' work
git push --force-with-lease origin "ci/bot-branch"

In CI

Prefer --force-with-lease over --force: it refuses to overwrite work the remote received after your last fetch, preventing a stale CI runner from clobbering a teammate. Use --follow-tags so a release commit and its tag publish in one push. Authenticate with a token-bearing remote URL or credential helper.

Key takeaways

  • --force-with-lease is the safe force-push: it aborts if the remote moved since your fetch.
  • --follow-tags publishes a release commit and its annotated tag in a single push.
  • A plain push omits tags; use --tags or --follow-tags to include them.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →