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.

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.

Practice

A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.

Open practice playground

Go deeper with