CurriculumRemote Repositoriesgit push — Uploading Changes
Lesson 3 of 743%
Intermediate7 min+70 XP

git push — Uploading Changes

git push uploads your local commits to the remote repository, making your work available to teammates. Git only sends the new commits the remote does not have yet — it is efficient and incremental.

01.How Push Works

Push does not copy your entire working directory — it sends only the new commit objects (the delta) that the remote is missing. Git compresses and transmits only what is needed. After a push, the remote-tracking branch (origin/main) in your local repo is also updated to reflect the new state.

Distributed Architecture
💻
Your Local
push / pull
☁️
GitHub (Remote)
push / pull
💻
Teammate's Local

02.Setting Upstream with -u

The -u flag (short for --set-upstream) creates a tracking link between your local branch and the remote branch. You only need this once per branch. After running "git push -u origin main", all future pushes and pulls from that branch can use just "git push" and "git pull" with no arguments.

Branch Visualization
featuremainHEAD
main
feature
HEAD

Commands

commands — click to reveal output
$
git push origin main
Push local main branch to origin
▼ show output
$
git push -u origin main
Push AND set upstream tracking (only needed first time)
▼ show output
$
git push
Push to tracked upstream branch (after -u is set)
$
git push origin feature/login
Push a feature branch to remote
$
git push origin --delete feature/old
Delete a remote branch
▼ show output
$
git push --force-with-lease
Safe force push — only works if remote has no new commits you have not seen
KNOWLEDGE CHECK

What does the -u flag in "git push -u origin main" do?

Rate this lesson:
PreviousNext Lesson