In this lesson, you will learn how to connect an existing local Git project to a new GitHub repository so you can begin backing up and sharing your code.
Up until now, you have been managing your project history entirely on your own machine. While local commits are great for version control, they don't provide a way to collaborate with others or keep your work safe on a remote server. To bridge this gap, you need to tell your local Git repository exactly where its remote counterpart lives on GitHub.
Adding a Remote
Every Git project can track multiple "remotes," which are essentially URLs that act as shortcuts to a repository hosted online. The most common name for your primary remote is origin. To link your local project to a GitHub repository, you use the git remote add command followed by that name and the repository's URL:
git remote add origin https://github.com/username/repository-name.git
Once you run this command, Git stores this URL under the alias origin. You can verify this connection by running git remote -v, which will list the fetch and push URLs associated with your project.
Why This Matters
By initializing this tracking, you create a pipeline between your local terminal and the cloud. This simple link is the foundation for everything we have covered regarding teamwork and synchronization. Without this "remote," Git wouldn't know where to send your commits when you want to share them or where to fetch updates from when your teammates push new changes.
After running the command above, you are ready to push your local branches to GitHub, allowing your work to be visible to others and ensuring your project's history is preserved outside of your local machine.
Key Takeaway: Linking a local repository to GitHub via git remote add origin <url> creates the essential bridge required to synchronize your local history with a shared remote workspace.