
Module 5 Lesson 1: Adding and removing remotes
Connect your local machine to the cloud. Learn how to manage 'Remotes'—the links that allow your repository to talk to GitHub, GitLab, or your team's private servers.
Module 5 Lesson 1: Adding and removing remotes
Everything we've done so far has happened on your local computer. But Git's true power is collaboration. To share your code or download others' work, you need to connect your local repository to a Remote.
In this lesson, we learn how to manage these connections using the git remote command.
1. What is a Remote?
A remote is simply a URL pointing to a copy of your repository stored on another server (like GitHub, GitLab, or a company server).
A single local repository can have multiple remotes. For example, you might have one remote for your personal backup and another for the official team project.
2. The origin Convention
When you git clone a repository, Git automatically creates a remote named origin.
originis just a nickname. Git uses it by default, but you could call itcloud,backup, orserverif you wanted.
3. Managing Remotes
Adding a Remote
If you started a project with git init, you need to manually connect it to the cloud:
git remote add origin https://github.com/username/project.git
Viewing Remotes
To see which remotes are currently configured:
git remote -v
(The -v stands for "verbose," showing you the fetch and push URLs).
Renaming and Removing Remotes
If you made a typo or moved your project to a new server:
# Rename 'origin' to 'github'
git remote rename origin github
# Remove a connection entirely
git remote remove github
Changing the URL
If you switched from HTTPS to SSH:
git remote set-url origin git@github.com:username/project.git
graph LR
Local["Local Repo"] -- "git remote add" --> URL["https://github..."]
URL -- "Nickname" --> Origin["origin"]
Origin -- "git push" --> GitHub["GitHub Server"]
4. Multiple Remotes: The "Upstream" Pattern
In open-source development, you often have two remotes:
origin: Your personal "fork" (copy) of the project where you have permission to save changes.upstream: The original "official" project. You use this to download the latest updates from the main maintainers.
Lesson Exercise
Goal: Configure a remote nickname.
- Go to your
git-practicerepo. - Run
git remote -v. It should be empty. - Pretend you have a GitHub project. Run
git remote add origin https://github.com/example/practice.git. - Run
git remote -vagain. Do you see the "origin" nickname mapped to the URL? - Rename "origin" to "cloud".
- Remove "cloud".
Observation: You'll see that remotes are just "address book entries" for your repository. They don't send any data yet; they just tell Git where the data should go when you're ready.
Summary
In this lesson, we established:
- Remotes are external links to other copies of your repository.
originis the default name given to the primary remote.git remote add,rename,remove, andset-urlare your management tools.- A repository can have multiple remotes for different purposes (e.g., origin vs upstream).
Next Lesson: Now that we have an address, let’s send some data. Welcome to Lesson 2: Pushing and pulling changes.