learn git.
0/25 done
learn git/remotes and beyond/course 22 of 25

git push: upload your work

From your computer to the internet, in one move.

7 min read·3 sections·2 tasks
the key idea

git push sends your new commits to the remote — and -u on the first push makes every later push a one-word command.

01Connect before you push

Your local repository starts with no remote — it does not know the internet exists. First, introduce it to one: git remote add origin <url>. From that moment the nickname origin points at that URL, and every push and pull knows where to go. Check the wiring any time with git remote -v, which prints each remote's name and address.

[bash]· the introduction
git remote add origin https://github.com/you/my-project.git
git remote -v
Where the URL comes from

On GitHub, after creating an empty repository, the site shows you exactly these two commands with your URL filled in. You copy them once and never think about it again.

02The first push explains itself

A brand-new remote is empty — it has no branches at all. So the first push has to say where and what: git push -u origin main means push to origin, the branch main. The -u remembers the pair — upstream — so that from now on, standing on main, a bare git push knows exactly what you mean.

Git answers with upload statistics you can safely ignore, and one line that matters: * [new branch] main -> main — the remote just gained your branch, its very first one.

[bash]· first time, and every time after
git push -u origin main
git push

03Pushing nothing new

Push with nothing to send and git answers Everything up-to-date — the remote already has every commit you have. Not an error; a confirmation. The healthy daily loop grows one step: work, commit, push, repeat. Pushing often means your backup is always fresh and teammates are never waiting on you.

Push is public

Once pushed, your commits exist on the shared remote where others can see and build on them. Push finished, reviewed work; keep experiments on their own branch.

The full sequence, once per project

remote add origin <url> → push -u origin main → then just git push forever after. Two commands once, one word always.

>>

Practice

A local project is ready. Publish it.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project (main) $
Your tasks0/2 done
  1. 01.Connect the remote: add origin with the URL https://github.com/you/my-project.git

    hint: Try: git remote add origin https://github.com/you/my-project.git

  2. 02.Push main to origin, with -u so it remembers.

    hint: Try: git push -u origin main