Skip to content
LatchkeyLatchkey home

git push: Usage, Options & Common CI Errors

git push sends your local branch commits to a remote repository.

Pushing publishes your work. Most CI push failures are auth, protected branches, or a remote that moved ahead of you.

What it does

git push updates remote refs (branches/tags) using your local commits and uploads the objects needed to complete them.

Common usage

Terminal
git push                              # to the tracked upstream
git push -u origin feature           # push + set upstream
git push origin --tags               # push all tags
git push --force-with-lease          # safer force push

Options

FlagWhat it does
-u / --set-upstreamRecord the remote branch as upstream
--force-with-leaseForce only if remote matches your last fetch
--tagsPush tags as well
--deleteDelete a remote ref
--atomicAll-or-nothing for multiple refs

Common errors in CI

! [rejected] main -> main (non-fast-forward) / "Updates were rejected because the remote contains work that you do not have locally" - fetch and rebase, then push: git pull --rebase origin main. "remote: Permission to owner/repo.git denied" means the token lacks write/contents permission. On protected branches a direct push may be blocked entirely.

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

Frequently asked questions

git push: Usage, Options & Common CI Errors?
Pushing publishes your work. Most CI push failures are auth, protected branches, or a remote that moved ahead of you.
What it does?
git push updates remote refs (branches/tags) using your local commits and uploads the objects needed to complete them.
Common errors in CI?
! [rejected] main -> main (non-fast-forward) / "Updates were rejected because the remote contains work that you do not have locally" - fetch and rebase, then push: git pull --rebase origin main. "remote: Permission to owner/repo.git denied" means the token lacks write/contents permission.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card