Linking Local Repositories: Connecting Git to GitHub
Learn how to create a GitHub repository and use git remote to link your local project to the cloud, enabling professional version control workflows.

Previously in this course, we covered the critical setup steps for secure interaction with cloud platforms, including Introduction to GitHub: Git vs. GitHub Explained and SSH Key Authentication: Secure Git Access for Beginners. Now that your environment is authenticated, we need to establish a formal connection between your local files and the remote world.
The Concept of a "Remote"
In Git, a "remote" is simply a pointer to a version of your repository hosted elsewhere—usually on a server like GitHub. While your local repository tracks the full history of your project, the remote serves as the central "source of truth" that allows for backup, collaboration, and deployment.
By convention, the first remote you add is named origin. Think of this as the "home base" for your project. Adding a remote does not move your files; it merely tells your local Git configuration where to send your data when you decide to share your progress.
Creating a Remote Repository on GitHub
Before running any commands in your terminal, you must create the "empty shell" on GitHub where your code will live.
- Log in to GitHub.
- Click the + icon in the top-right corner and select New repository.
- Give your repository a name (e.g.,
my-first-project). - Important: Do not initialize the repository with a README, license, or gitignore at this step. Since you already have a local project initialized via Initializing a Repository: Start Your Git Project Today, you want to avoid conflicting history.
- Click Create repository.
GitHub will provide you with a screen containing a URL. Make sure you select the SSH option (which looks like git@github.com:username/repo-name.git) rather than the HTTPS option, as we configured your SSH Key Authentication in the previous step.
Adding a Remote Origin
With the repository created on GitHub, you are ready to link your local project. Open your terminal, navigate to your project directory, and use the git remote command.
Bash# Add the remote repository git remote add origin git@github.com:your-username/your-repository-name.git
How to Verify the Connection
To ensure the link was created successfully, you can list your remotes:
Bashgit remote -v
You should see output indicating that origin is mapped to your GitHub URL for both fetch and push operations.
| Action | Command | Purpose |
|---|---|---|
| Add | git remote add origin <url> | Links your local repo to the remote |
| Verify | git remote -v | Displays the current remote connections |
| Rename | git remote rename origin upstream | Changes the nickname of the remote |
| Remove | git remote remove origin | Unlinks the remote connection |
Hands-on Exercise
- Create the Remote: Follow the steps above to create an empty repository on your GitHub account.
- Link: Copy the SSH URL provided by GitHub and run
git remote add origin <your-ssh-url>inside your local project folder. - Confirm: Run
git remote -v. You should see your URL listed twice (one for fetching, one for pushing). - Clean up (Optional): If you made a typo, you can remove the remote using
git remote remove originand run the add command again.
Common Pitfalls
- "Remote origin already exists": If you see this error, you likely added the remote previously. Use
git remote -vto check, or if the URL is wrong, usegit remote set-url origin <new-url>to correct it. - HTTPS vs. SSH: If you try to push later and it asks for a username/password, you likely used the HTTPS URL instead of the SSH URL. Always double-check your
git remote -voutput. - Initializing with README: If you accidentally checked the "Initialize this repository with a README" box on GitHub, your local and remote histories will diverge. You will have to pull that file down to your local machine before you can push your existing work.
Recap
Linking local repositories is the bridge between your private work and the global developer community. By creating a repository on GitHub and using git remote add origin to point your local terminal to that URL, you’ve prepared your project for its first synchronization.
Up next: Now that your local repository knows where its "home base" is, we’ll move your commits to the cloud using git push.



