Reading 0%
Learning Path Git & GitHub Fundamentals

Connecting a Local Repository to GitHub

Learn how to connect your local repository to GitHub and establish a remote relationship between them.

Connecting a Local Repository to GitHub

Introduction

You now have two separate repositories. One exists on your computer and the other exists on GitHub. Although they may represent the same project, Git currently treats them as completely independent repositories.

Before Git can synchronize commits between your computer and GitHub, the two repositories must be connected.

In this guide, you'll learn how Git remotes work, how to connect a local repository to GitHub, and how to verify that the connection was created successfully.

Why Connecting Repositories Matters

Git cannot automatically know where your GitHub repository is located. You must explicitly tell Git which remote repository should be associated with your local project.

Once connected, Git can send commits to GitHub and retrieve changes from GitHub whenever needed.

Real World Example

Imagine your local repository is your laptop and GitHub is a secure cloud storage vault. Before files can move between them, you must establish a connection that tells both locations how to communicate.

Remote Repository Mental Model

Think of a remote repository as a destination that your local repository knows how to communicate with.

A remote is simply a saved connection between your local Git repository and another repository hosted elsewhere.

Local Git repository connected to a remote GitHub repository
A remote connection allows Git to communicate with GitHub.

Simple Mental Model

A remote is a saved address that tells Git where your GitHub repository lives.

Locate Your Repository URL

Before creating the connection, you need the URL of your GitHub repository.

STEP 01

Open Your GitHub Repository

Navigate to the repository you created in the previous guide.

Open the repository's main page on GitHub.

STEP 02

View Repository Connection URL

If the repository is empty, GitHub displays a Quick setup section that contains the repository URL.

If the repository already contains files, click the Code button to view available repository URLs.

Choose HTTPS and copy the repository URL.

GitHub Code button showing repository URL
STEP 03

Copy The HTTPS URL

Copy the repository URL shown in the HTTPS tab.

The URL should resemble your GitHub repository address.

Example Repository URL

https://github.com/username/my-first-project.git

STEP 04

Open Git Bash

Open Git Bash and navigate to your local repository.

Use the repository you've been building throughout this learning path.

bash
cd ~/my-first-project
Git Bash
[user@computer MINGW64 ~]
$ cd ~/my-first-project

[user@computer MINGW64 ~/my-first-project (main)]
$

Create The Remote Connection

Git stores remote repository connections using names. By convention, the primary GitHub repository is usually named origin.

STEP 05

Add The GitHub Repository As A Remote

Use git remote add to create the connection.

Replace the example URL with your actual GitHub repository URL.

bash
git remote add origin https://github.com/username/my-first-project.git
Git Bash
[user@computer MINGW64 ~/my-first-project (main)]
$ git remote add origin https://github.com/username/my-first-project.git

[user@computer MINGW64 ~/my-first-project (main)]
$

Git typically produces no output when the command succeeds.

Verify The Remote Connection

After creating the remote, it's important to verify that Git saved the connection correctly.

STEP 06

View Configured Remotes

Run git remote -v to display all configured remote repositories.

The URL should match your GitHub repository.

bash
git remote -v
Git Bash
[user@computer MINGW64 ~/my-first-project (main)]
$ git remote -v

origin  https://github.com/username/my-first-project.git (fetch)
origin  https://github.com/username/my-first-project.git (push)

Git now knows where your GitHub repository is located.

Entry Purpose
fetch Download changes from GitHub
push Upload changes to GitHub

Both operations use the same repository URL, but Git displays them separately because fetching and pushing are distinct actions.

Understanding Origin

The name origin is not special to Git. It is simply the conventional name developers use for the primary remote repository.

You could technically use another name, but origin is considered the standard and is used in most tutorials and professional workflows.

Common Remote Names

origin is the primary repository. Additional remotes may be added later for team workflows, forks, or backup repositories.

Common Beginner Mistakes

Mistake Why It Happens Better Habit
Using the wrong repository URL Copying the wrong address Always verify the URL before adding the remote
Forgetting origin Unfamiliar terminology Remember origin is the standard remote name
Thinking add uploads files Confusing connection with synchronization Understand remote add only creates the relationship
Skipping verification Assuming success Run git remote -v after adding a remote

Why This Step Matters

Connecting a local repository to GitHub is the bridge between local version control and cloud-based collaboration.

Without a remote connection, Git cannot exchange commits with GitHub. Every future push, pull, fetch, and synchronization operation depends on this relationship.

Conclusion

In this guide, you learned how to find your GitHub repository URL, add a remote connection using git remote add origin, and verify the connection using git remote -v.

Key Takeaway

A remote connection tells Git where your GitHub repository lives. Creating that connection allows your local repository and GitHub repository to communicate with each other.

Next in Learning Path

Pushing and Pulling Changes

Git & GitHub Fundamentals

Continue Learning →