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)

  1. You go to github.com → New repository

    • Name: todo-app-2026
    • Add README file (checked)
    • Create repository
  2. GitHub shows you this big green box with commands:

    text

    The important line is:

    Bash

    That’s it — that single command sets the remote.

  3. After running it, check:

    Bash

    You see:

    text

    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)

  1. You already have local repo with commits:

    Bash
  2. 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
  3. 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

  4. Run in your local repo folder:

    Bash
  5. Set default branch name (only needed once per repo)

    Bash
  6. Push (send your local history to GitHub)

    Bash

    -u = set upstream → remembers that main tracks origin/main From now on you can just do git push or git pull

  7. Verify:

    Bash

    You should see:

    text

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! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *