Push to GitHub
Upload your code
⏱ Est. ~7 min
01 · Read
You know GitHub puts your code online. Now let's actually push something to it. Push is the git command that uploads your local commits to a remote repo.
It's a two-step setup: first tell git where to push (link it to a GitHub URL), then push your commits. After the first setup, pushing later is a single command.
💡 Picture thisThink of it as setting up mail forwarding. First tell the post office your new address (git remote add), then send the package (git push). After that, the post office remembers where to send things.
Key points
- git remote add origin URL connects your local repo to GitHub
- git push -u origin main uploads your commits for the first time
- After the first push, just git push is enough
02 · Terminal exercise
Let's set up a project and push it to GitHub. Initialize the repo first.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
Stage all the files.
(This section is interactive — please enable JavaScript.)
04 · Fill in the blank
The conventional name for your main GitHub remote is ___.
05 · Terminal exercise
Commit your files.
(This section is interactive — please enable JavaScript.)
06 · Terminal exercise
Connect your local repo to GitHub. origin is the conventional name for "your GitHub connection," and the URL is your project's address on the web.
(This section is interactive — please enable JavaScript.)
07 · Terminal exercise
Upload your code to GitHub. The -u flag remembers this connection so pushing later is easier.
(This section is interactive — please enable JavaScript.)
08 · Quiz
In git push -u origin main, what does the -u flag do?
- Undoes the push if something goes wrong
- Uploads only uncommitted files
- Updates the remote's URL
- Remembers the connection so future pushes are just git push
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.