Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Remotes and Collaboration

git push command

Reference for git push: send commits to a remote and update its branches and tags. Options -u, --tags, --delete, --force-with-lease, --atomic, refspecs and push.default.

git push sends your commits to another repository and asks it to move one or more refs (branches or tags) to match. Git uploads only the objects the remote lacks, then the remote checks whether each update is allowed: by default a branch may only move forward, so the new tip must contain the old one.

If someone else pushed in the meantime, your push is rejected as "non-fast-forward". You then fetch, integrate (merge or rebase) and push again. Overwriting remote history requires an explicit force, covered in force-with-lease.

Terminal
git push [<options>] [<remote> [<refspec>...]]
git push -u origin <branch>
git push origin --delete <branch>

Try it

Bash First push, upstream and rejection

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Tags, deleting branches and --dry-run

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

A refspec for push is [+]<src>:<dst>: push local <src> to remote ref <dst>. main alone means main:main; HEAD:refs/heads/new creates a branch with another name; an empty <src> (:topic) deletes topic.

Option Description
-u, --set-upstream Record the remote branch as the upstream of the local branch, so later git push and git pull need no arguments.
--all, --branches Push all local branches.
--tags Push all tags (and the refspec list). --follow-tags pushes only annotated tags that point at pushed commits.
-d, --delete Delete the named remote refs.
-n, --dry-run Do everything except the update.
-f, --force Allow non-fast-forward updates. See force-with-lease.
--force-with-lease Force only if the remote ref is still what you last saw.
--atomic Update all refs or none, if the server supports it.
-o <option>, --push-option=<option> Send a string to the server's hooks (for example CI hints).
--mirror Make the remote an exact copy: refs are created, updated and deleted to match.
--prune Delete remote refs that have no local counterpart (within the refspec).
--no-verify Skip the pre-push hook.
--signed[=true|false|if-asked] GPG-sign the push certificate.
--progress, -q, -v Control output.

Config: push.default (simple is the default: push the current branch to the same-named upstream branch and refuse if names differ; also current, upstream, matching, nothing), push.autoSetupRemote (set upstream on the first push automatically), push.followTags, remote.<name>.push.

Usage notes

  • Rejections ("fetch first" or "non-fast-forward") are a safety feature. Do not reach for --force; fetch and integrate, or use --force-with-lease if you rewrote your own branch.
  • A new branch needs an upstream or an explicit target: git push -u origin feature. With push.autoSetupRemote=true, a plain git push does it.
  • Tags are not pushed with branches unless you use --follow-tags or --tags. Deleting a tag remotely is git push origin --delete v1.0 (or :refs/tags/v1.0).
  • Pushing to a checked-out branch of a non-bare repository is refused by default (receive.denyCurrentBranch), which is why shared repositories are bare.
  • Server-side hooks (pre-receive, update, post-receive) and branch protection on hosting sites can reject a push even when it is a fast-forward; their messages arrive prefixed remote:.
  • --mirror and --prune can delete remote branches; use --dry-run first.
  • Exit status is non-zero when any ref update failed.