Walkthrough — Stage 8: Push to GitHub
Command: git push -u origin main
git push -u origin mainWhat's happening:
Four tokens, each with a job:
git push— the command. It uploads commits from your local branch to a remote branch.-u— the "set upstream" flag. It tells Git to remember a default mapping between your localmainand the remote'smainonorigin. After this one-time flag, you can just rungit pushorgit pullwith no arguments.origin— the remote to push to. This is the name you gave in Stage 7 when you rangit remote add origin ....main— the local branch to push. You are pushing yourmainto the remote'smain.
Everything you have ever committed to main now exists on GitHub.
What the -u flag actually does
Without -u, Git has no default for git push or git pull on this branch — you would have to type the remote and branch every time. With -u, Git writes a small block to .git/config:
[branch "main"]
remote = origin
merge = refs/heads/mainFrom then on, Git knows that main is linked to origin/main. You only set this up once per branch, the first time you push it.
Authentication on the first push
The first git push on a new machine triggers an authentication prompt. Modern GitHub does not accept account passwords over HTTPS — you need a personal access token (PAT).
How to create one:
- On github.com, go to Settings → Developer settings → Personal access tokens → Tokens (classic).
- Click Generate new token (classic).
- Give it a name like "box-runner tutorial."
- Check the repo scope.
- Generate and copy the token (it starts with
ghp_). - When Git asks for your password during push, paste the token.
Your operating system's credential helper usually caches the token, so you only do this once.
Reading the push output
A successful push prints something like:
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
...
To https://github.com/<your-username>/box-runner.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.The last two lines are the important ones:
[new branch] main -> main— a brand-new branch was created on the remote.branch 'main' set up to track 'origin/main'— the-uflag did its job.