Push
_Git · Reference cheat sheet_
Push
Git · Reference cheat sheet
📖 Overview
git push uploads local commits (and optionally tags) to a remote. Set an upstream once with -u, prefer --force-with-lease over --force, and push tags deliberately.
🧩 Core concepts
- Upstream —
-urecords remote/branch for futurepush/pull. - Fast-forward — remote tip must be ancestor unless forced.
- Force-with-lease — refuses overwrite if remote moved unexpectedly.
- Refspecs —
git push origin local:remotemaps branches explicitly. - Tags —
git push --tagsor push a single tag by name. - Delete remote branch —
git push origin --delete branch.
💡 Examples
# First push of a feature branch
git push -u origin feature/checkout
# Subsequent pushes
git push
# Push to explicit remote/branch
git push origin main
# Safe force after rebase (preferred)
git push --force-with-lease origin feature/checkout
# Push one tag / all tags
git push origin v1.2.0
git push --tags
# Delete remote branch
git push origin --delete feature/checkout
# Dry run
git push --dry-run⚠️ Pitfalls
--forcecan destroy others’ commits — use--force-with-leaseand branch protections.- Pushing to the wrong remote/branch is common with multiple remotes — check
git remote -v. - Large binary blobs bloat history — use Git LFS before the first push.
- CI/CD may reject unsigned commits or unprotected force pushes on
main.