Git & GitHub ยท Chapter 23 of 42

Git Remotes

A remote is a version of your repository hosted elsewhere, typically on a service like GitHub. Remotes let you share your work with others and pull in changes they've made.

The default remote name when you clone a repository is `origin`, but you can add multiple remotes and give them any name you like.

Syntax
git remote -v
git remote add origin <url>

Viewing remotes

Run `git remote -v` to list configured remotes and their URLs, showing both fetch and push addresses.

Adding and removing remotes

Use `git remote add name url` to connect a new remote, and `git remote remove name` to disconnect one.

Example 1 (bash)
git remote add origin https://github.com/user/repo.git

Connects the local repository to a GitHub repository named 'origin'.

Example 2 (bash)
git remote -v
Output
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Lists the configured remote and shows its URL for both fetching and pushing.

Key points

  • A remote is a hosted version of your repository, usually on GitHub.
  • The default remote name is origin.
  • git remote -v lists configured remotes and their URLs.
  • You can have multiple remotes with different names.
๐Ÿ’ก Note: You can add a second remote (e.g., 'upstream') when working with forks, to track the original project separately from your own copy.

๐Ÿ“ Quick Quiz

1. What is a Git remote?

2. What is the default name for a remote after cloning?

3. Which command lists configured remotes?