Git Remote — Linking Local Repository with GitHub

Now, let’s move to a very practical step — linking your local Git repo with a remote GitHub repo.


Local Setup

I created a new folder:

mkdir git-remote-demo-youtube
cd git-remote-demo-youtube
git init

Then added a file:

echo "hello" > file.txt
git add file.txt
git commit -m "first commit"

At this point, our local repo has only one commit.


Checking Existing Remotes

To see if your repo is connected to any remote:

git remote

👉 Output is empty because we haven’t linked anything yet.


Creating a Remote on GitHub

  1. Login to GitHub.
  2. Click New Repository.
  3. Name it git-remote-demo-youtube (or anything you like).
  4. Keep it Public for now.
  5. Click Create Repository.

GitHub gives you two URLs:

  • HTTPS URL
  • SSH URL

Both can connect your repo, but ⚡ SSH is more secure (we’ll use that here).


Linking Remote Repo

Copy the SSH URL and add it:

git remote add origin git@github.com:your-username/git-remote-demo-youtube.git

Here:

  • origin → The default name for your remote.
  • You could use another name (like github or myrepo), but origin is the convention.

Verifying the Remote

Check if the remote was added:

git remote

Output:

origin

To see the URL and details:

git remote -v
origin  git@github.com:your-username/git-remote-demo-youtube.git (fetch)
origin  git@github.com:your-username/git-remote-demo-youtube.git (push)

👉 This means:

  • Fetch (pulling changes) and Push (sending changes) both use this URL.
  • If needed, you can configure fetch and push URLs separately.

Key Notes

  • git remote add <name> <url> → Adds a remote.
  • git remote -v → Shows all remotes with URLs.
  • Default name origin is used when you clone a repo.
  • You can add multiple remotes (e.g., origin, upstream, backup).

What’s Next?

In the next blog, we’ll push this first commit to GitHub using:

git push origin main

and fix authentication issues (SSH keys setup).


Keep Learning 🚀

👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.

👉 My YouTube Channel – More videos, more fun, and lots of learning!

👉 📺 Watch this topic in video form

Stay curious, keep coding, and let’s make learning fun together! 🎉