By admin , 29 April 2026

Synopsis

git push [<remote> [<refspec>...]] [--force-with-lease] [--tags] [--delete]

Description

The git push command sends local commits to a remote repository, updating remote branches to match your local ones. The first push of a new branch typically requires -u to set up tracking. By default, push is non-destructive: it refuses to overwrite remote history that you don't have locally. Use --force-with-lease when you genuinely need to rewrite remote history (after a rebase) — never use plain --force on shared branches.

Push obeys server-side rules: branch protections, required reviews, signed commits, and pre-receive hooks can all reject a push. Read the error message carefully when this happens.

In day-to-day use, git push integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git push --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git push interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git push's side effects helps avoid all three.

Common Options

OptionDescription
-u, --set-upstreamSet upstream for future push/pull defaults.
--force-with-leaseForce push only if remote ref matches your last fetched value.
--force / -fForce-overwrite remote history (dangerous on shared branches).
--tagsPush all local tags.
--deleteDelete a remote branch.
--dry-runShow what would be pushed.
--allPush all branches.
--atomicAll-or-nothing update of multiple refs.

Examples

git push -u origin feature/login
# First push of a new branch with tracking

git push --force-with-lease
# Safer alternative to --force after rebasing

git push origin --delete old-feature
# Delete a remote branch

git push --tags
# Publish all local tags

Common Mistakes

Plain --force can wipe out colleagues' commits. Use --force-with-lease instead. Pushing to main directly bypasses code review on many teams — set up branch protection. Forgetting -u means future git push commands need explicit arguments.

Related Commands

git fetch, git pull, git remote, git tag