git remote
Manage connections to remote repositories, controlling where you push and fetch code from.
Your local Git repository can track multiple remote repositories—the main
project on GitHub, your personal fork, a staging server, or your teammate's
fork. git remote manages these connections, letting you add, remove, rename,
and inspect the remote repositories your local repo knows about.
Running git remote with no arguments lists your configured remotes by name.
Most repositories have at least one remote called origin, which is automatically
created when you clone. Running git remote -v shows more detail, displaying
the URLs for fetching and pushing for each remote.
To add a new remote, use git remote add name url. For example, when working
with forks, you might add the original repository as upstream with
git remote add upstream https://github.com/original/repo.git. Now you can
fetch updates from upstream while pushing to your origin fork. Multiple remotes
let you pull from one place and push to another, or collaborate with multiple
repositories simultaneously.
Removing remotes uses git remote remove name, and renaming them uses
git remote rename old-name new-name. These operations only affect your local
configuration—they don't touch the remote repositories themselves, just your
local references to them.
Understanding remotes means understanding that Git is decentralized. Your local repository is independent, and remotes are simply saved references to other repositories you want to sync with. You control which remotes exist and how you use them.
