Chapter 21: Git Set Remote from GitHub
Git remote — and especially how to set / add / change the remote URL from GitHub (the line that connects your local repository to the one on github.com)
Many beginners get confused here and think “I created the repo on GitHub, why can’t I just push?” The answer is: Git doesn’t magically know where your GitHub repository lives — you have to tell it explicitly using the git remote command.
What does “remote” actually mean?
A remote in Git is just a named shortcut to another Git repository (usually on the internet).
- Most common name = origin (convention — almost everyone uses it)
- The URL can be HTTPS or SSH
- Once set, instead of typing the full URL every time, you just write git push origin main
Think of it like saving a contact in your phone:
- Without contact: you type full number every call → +91-98765-43210
- With contact: you save it as “Mummy” → just call “Mummy”
origin = “GitHub repo”
When do you need to set a remote?
Two very common situations in 2026:
Situation A (most beginners start here) You created the repository first on GitHub (with README, .gitignore, license…) → GitHub gives you ready-made commands to copy-paste
Situation B (what we did in earlier lessons) You created the repository first on your laptop with git init → You need to connect it to GitHub afterwards
We’ll do both examples today.
Example 1 – GitHub created first → copy-paste from GitHub (easiest)
-
You go to github.com → New repository
- Name: todo-app-2026
- Add README file (checked)
- Create repository
-
GitHub shows you this big green box with commands:
text01234567891011121314…or create a new repository on the command lineecho "# todo-app-2026" >> README.mdgit initgit add README.mdgit commit -m "first commit"git branch -M maingit remote add origin https://github.com/Webliance/todo-app-2026.gitgit push -u origin mainThe important line is:
Bash0123456git remote add origin https://github.com/Webliance/todo-app-2026.gitThat’s it — that single command sets the remote.
-
After running it, check:
Bash0123456git remote -vYou see:
text01234567origin https://github.com/Webliance/todo-app-2026.git (fetch)origin https://github.com/Webliance/todo-app-2026.git (push)Now git push knows where to go.
Example 2 – You created repo locally first → connect to new GitHub repo
(This is what we did in “Git + GitHub Getting Started” lesson)
-
You already have local repo with commits:
Bash01234567git log --oneline# shows your commits -
Create empty repo on GitHub (very important: do NOT check “Add a README file”)
- New repository → name: todo-app-2026 → no README, no .gitignore, no license → Create
-
Copy the SSH or HTTPS URL from the green “Quick setup” box:
HTTPS: https://github.com/Webliance/todo-app-2026.git SSH: git@github.com:Webliance/todo-app-2026.git
-
Run in your local repo folder:
Bash012345678git remote add origin https://github.com/Webliance/todo-app-2026.git# or better (if SSH is set up):# git remote add origin git@github.com:Webliance/todo-app-2026.git -
Set default branch name (only needed once per repo)
Bash0123456git branch -M main -
Push (send your local history to GitHub)
Bash0123456git push -u origin main-u = set upstream → remembers that main tracks origin/main From now on you can just do git push or git pull
-
Verify:
Bash01234567git remote -vgit branch -vvYou should see:
text0123456789origin git@github.com:Webliance/todo-app-2026.git (fetch)origin git@github.com:Webliance/todo-app-2026.git (push)main abc1234 [origin/main] Add dark mode toggle
Everyday Remote Commands Cheat Sheet (save this)
| What you want to do | Command Example | Notes / When to use |
|---|---|---|
| Add new remote (most common) | git remote add origin https://… | First time connecting local → GitHub |
| Change existing remote URL | git remote set-url origin git@github.com:… | Switching HTTPS → SSH or wrong URL |
| Show all remotes & URLs | git remote -v | Most used command to check |
| Rename remote | git remote rename origin upstream | Rare – usually keep origin |
| Remove remote | git remote remove origin | Careful — disconnects push/pull |
| Add multiple remotes | git remote add upstream https://github.com/org/repo.git | Forked repo workflow (origin = your fork) |
| Push to specific remote/branch | git push origin main | Explicit (safer than plain git push) |
| Set upstream tracking (remember association) | git push -u origin feature/new-ui | After first push of new branch |
Quick 2026 Tips
- Prefer SSH once set up (passwordless) → see our previous “Git Security SSH” lesson
- Never push sensitive data — even if remote is private
- If GitHub shows “src refspec main does not match any” → you forgot git branch -M main or no commits yet
- Corporate network blocks SSH? → stick with HTTPS + PAT or credential helper
Got the “set remote” feeling now? It’s literally just telling Git where your GitHub home is.
Next?
- Want to practice switching HTTPS ↔ SSH on a real repo?
- Fork + upstream workflow (common in open source)?
- Or move to pull requests / merge conflicts?
Just tell me — we’ll continue step by step. You’re doing excellent! 🚀
