All commands

git push

intermediate

Upload your branch's commits and advance the remote branch.

What it does

git push sends your local commits (objects your remote doesn't have) up the wire, then updates the remote's branch ref to match yours. By default it only pushes the current branch to its upstream. The remote's version of you is updated; nothing local is changed.

Your machine

local repository

mainahead ⇗
new objects uploaded → origin/main

Remote origin

everything.git

refs/heads/main← advances

Your new objects travel up; the remote branch ref advances to match you

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 4

Step 1

Share your commits

You've committed locally. The remote doesn't have those objects yet — they're about to travel up.

git push

Your machine

local repository

mainahead ⇗
new objects uploaded → origin/main

Remote origin

everything.git

refs/heads/main← advances

Your branch is ahead — the upload starts

Under the hood

1

Upload-pack negotiation, reversed

Push tells the remote what you have; the remote answers with what it still lacks; only the missing objects are sent — packed and delta-compressed.

2

The ref update is a claim of ancestry

Pushing branch main means: 'here are my objects, and my main is a descendant of your main.' If it's NOT (you're behind), the remote refuses with a rejected/non-fast-forward error — protecting the remote history from being orphaned.

3

Force-push overrides the guard

`git push --force` ignores the ancestry check. That's the forbidden-words of git: it rewrites the remote branch. Always --force-with-lease, which only forces if the remote matches what you last saw — making accidental history-wipes nearly impossible.

4

Tags travel separately

Branches push branches; tags need `git push --tags` (or --follow-tags) to ride along. The refspec syntax `git push origin main:feature` lets you publish your main as a different branch name on the remote.

Aliases the pros type

Memorize the git push concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git push
AliasWhy people use it
g pu

Push the current branch.

g puf

First-time push: sets upstream and publishes in one.

g pushf

The SURVIVAL push — only overwrite what you saw.

g pd

Delete a remote branch from the terminal.

Command anatomy

git push [<remote>] [<branch>]
-u

Set upstream — link local branch to remote one for future pulls/pushes.

--force-with-lease

Force the update only if the remote matches what you last fetched.

--tags

Push all tags along with branches.

--delete <b>

Delete a branch on the remote.

When to reach for it

Publishing a feature branch for a PR: git push -u origin feature/x.

Sharing your newest local commits with the team after pulling and rebasing clean.

Cleaning up a merged remote branch: git push origin --delete feature/x.

Pro tip

Rejected upstream? You tried to fast-forward nothing — the remote is ahead. `git pull --rebase` first, then push. That two-step rhythm (pull --rebase, push) is the daily heartbeat of collaborative branches, and it never force-pushes by accident.

Go deeper with