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
# 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.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # history, tags, and git describe all need this
- run: |
git rev-parse --is-shallow-repository # expect false
git rev-parse --abbrev-ref HEAD # prints HEAD when detachedKey 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.