Connecting to GitHub
Your repo currently exists only on your machine. This lesson publishes it to GitHub, making it accessible from any device and giving you a backup.
Local vs. Remote
Your local repo is the copy on your machine — the .git/ folder you created with git init. The remote is a copy hosted on GitHub. The name origin is the conventional alias for the primary remote.
Create a Repo on GitHub
- Log into github.com.
- Click + (top-right) → New repository.
- Name it
my-first-repo. - Leave it Public (or Private if you prefer).
- Do not check "Add a README file" — you already have one locally.
- Do not add a
.gitignoreor license for now. - Click Create repository.
GitHub will show you setup instructions. You will use the SSH URL (starts with git@github.com:).
Connect Local to Remote
Copy the SSH URL from GitHub (looks like git@github.com:yourname/my-first-repo.git), then run:
git remote add origin git@github.com:<username>/my-first-repo.git
This tells Git: "the remote named origin lives at this URL."
Verify the connection
git remote -v
Output:
origin git@github.com:<username>/my-first-repo.git (fetch)
origin git@github.com:<username>/my-first-repo.git (push)
Two lines — one for fetching (downloading), one for pushing (uploading).
Push Your Code
git push -u origin main
What each part means:
git push— upload commits to the remote-u— setorigin mainas the upstream for this branch (so futuregit pushwith no arguments knows where to go)origin— the remote namemain— the local branch to push
Output:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 272 bytes | 272.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:<username>/my-first-repo.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Refresh your GitHub repo page. Your README is now online.
Push Subsequent Changes
After the first push, you never need -u again for the same branch:
echo "Added from lesson 2.6" >> README.md
git add README.md
git commit -m "Add note from lesson 2.6"
git push
git push with no arguments pushes the current branch to its tracked upstream.
Summary
| Command | What it does |
|---|---|
git remote add origin <url> | Register a remote called origin |
git remote -v | List registered remotes |
git push -u origin main | Push and set upstream (first time) |
git push | Push to the already-set upstream |