# git push Command: Publish Refs in CI

> git push uploads commits and tags to a remote. Reference for --tags, --follow-tags, and --force-with-lease as used to publish releases safely from CI.

Source: https://latchkey.dev/learn/command-reference/git-push-command-reference  
Updated: 2026-06-26

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.

## 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.

```.github/workflows/ci.yml
- 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 detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### git push Command: Publish Refs in CI?

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.

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
