Git & GitHub Course
Git & GitHub
/
Beginner

git push

Definition

Uploads local repository content (commits and branches) to a remote repository.

Explain Like I'm New

The upload button. You finished your feature, you made your commits locally, but your boss can't see them yet. `git push` takes your local timeline and sends it up to GitHub for everyone to see.

Real World Example

You finish your work for the day, commit it, and run `git push origin main` so the server has a backup in case your laptop breaks overnight.

Common Use Cases

  • •Sharing code
  • •Backing up code to the cloud
  • •Publishing websites

Architecture & Flow

Terminal Output

bash / terminal
# 1. Save your work locally FIRST $ git commit -am "Finish the homepage" # 2. Upload that commit to the 'origin' server, on the 'main' branch $ git push origin main # 3. Create a brand new branch, and push it to the server for the first time # (-u sets the upstream link so Git remembers where to push next time) $ git checkout -b my-new-feature $ git push -u origin my-new-feature # 4. In the future, you can just type: $ git push

Interview Questions

basic

  • If you edit a file, can you just run `git push` immediately to save it to GitHub?

intermediate

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

Flash Cards

Question

Push immediately?

Click to reveal answer
Answer

No. `git push` ONLY uploads COMMITS. You must `git add` and `git commit` your changes first. Uncommitted changes are completely ignored by `git push`.

Question

What is the -u flag?

Click to reveal answer
Answer

It stands for 'set-upstream'. It links your local branch to the remote branch permanently. After using `-u` once, you can just type `git push` in the future instead of typing out `git push origin main` every time.