Terminal GuideTerminal Guide

git push Command Guide

Update remote refs along with associated objects

6 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git pushPush to tracked remote
git push origin mainPush to origin/main
git push -u origin mainPush and set upstream

Force

--forceForce push (dangerous)
--force-with-leaseSafer force push
--force-if-includesForce if ref included

Tags

--tagsPush all tags
origin <tag>Push specific tag
--delete origin <tag>Delete remote tag

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git push command uploads local commits to a remote repository. It's how you share your work with others.

bash
# Push to the tracked remote branch
git push

# Push to specific remote and branch
git push origin main

# Push current branch to remote
git push origin HEAD

Setting Upstream

Use -u to set the upstream branch for easier future pushes:

bash
# First push of a new branch (sets upstream)
git push -u origin feature-branch

# After setting upstream, just use:
git push

# Check what upstream is set
git branch -vv

Common Options

OptionDescription
-u, --set-upstreamSet upstream for the current branch
--allPush all branches
--tagsPush all tags
--forceForce push (overwrites remote)
--force-with-leaseSafer force push
--deleteDelete remote branch or tag
--dry-runShow what would be pushed

Force Pushing

Force push rewrites remote history. Use with extreme caution:

bash
# Force push (dangerous - overwrites remote history)
git push --force

# Safer force push (fails if remote has new commits)
git push --force-with-lease

# Force push specific branch
git push --force origin feature-branch
Warning
Never force push to shared branches like main or develop. It can overwrite your teammates' work and cause major confusion.

Pushing Tags

bash
# Push a specific tag
git push origin v1.0.0

# Push all tags
git push --tags

# Push commits and tags together
git push --follow-tags

# Delete a remote tag
git push origin --delete v1.0.0

Practical Examples

bash
# Standard workflow
git add .
git commit -m "Add feature"
git push

# Push new branch and set upstream
git checkout -b feature-x
git push -u origin feature-x

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

# Preview what would be pushed
git push --dry-run

# Push to different remote branch name
git push origin local-branch:remote-branch

# Push after rebase (use with care)
git push --force-with-lease

Frequently Asked Questions

What does "git push -u origin main" do?

It pushes your main branch to the origin remote and sets up tracking. After this, you can simply run "git push" without specifying the remote and branch.

What is the difference between --force and --force-with-lease?

--force overwrites remote history unconditionally. --force-with-lease only overwrites if no one else has pushed since your last fetch, preventing accidental overwrites of others' work.

Why does my push get rejected?

Usually because the remote has commits you don't have locally. Pull first (git pull), resolve any conflicts, then push again. Avoid force pushing to shared branches.

How do I push tags to the remote?

Use "git push origin <tagname>" for a specific tag, or "git push --tags" to push all tags. Tags are not pushed automatically with regular pushes.

How do I delete a remote branch?

Use "git push origin --delete <branch-name>" or the shorter syntax "git push origin :<branch-name>".

Summary

git push shares your commits with the remote repository. Always pull before pushing to avoid conflicts, and avoid force pushing to shared branches.

Quick Reference

  • git push - Push to tracked remote
  • git push -u origin <branch> - Push and set upstream
  • git push --tags - Push all tags
  • git push --force-with-lease - Safer force push

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles