← Back to Git Course | Chapter 4: Remote Repositories | Lesson 3 of 11

Git remote Command

git remote is like checking your phone's contacts list to see the nicknames of the other places your project is shared with, such as origin.
Syntax
bash
git remote
git remote add remote_name repository_url
git remote rename old_name new_name
git remote remove remote_name

Listing Remotes

git remote on its own lists the short names of every remote your repository knows about (usually just origin); add -v to also see the actual URLs each name points to, for both fetch and push.

Example: Listing Remotes

bash
git remote
git remote -v

Adding a Remote

git remote add <name> <url> connects your repository to an additional remote beyond the default origin -- useful when collaborating with a personal fork alongside the original project, or deploying the same code to two different hosts.

Example: Adding a Remote

bash
git remote add upstream https://github.com/original/repo.git

Renaming and Removing Remotes

git remote rename <old> <new> and git remote remove <name> let you clean up remote connections you've outgrown or misnamed, without affecting any of your actual commit history.

Example: Renaming and Removing Remotes

bash
git remote rename origin old-origin
git remote remove old-origin

Changing Remote URLs

If a repository migrates to a new host or your username changes, git remote set-url <name> <new-url> updates where an existing remote points without needing to remove and re-add it.

Example: Changing Remote URLs

bash
git remote set-url origin https://github.com/newuser/repo.git

Showing Detailed Remote Information

git remote show <name> prints detailed information about one specific remote -- its URL, which branches it tracks, and whether your local branches are ahead, behind, or diverged from their remote counterparts.

Example: Showing Detailed Remote Information

bash
git remote show origin
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Adding a remote with a typo in the URL, so git push fails, when git remote -v shows what is configured.
  2. Running git remote add origin ... when origin already exists, which gives remote origin already exists.
  3. Forgetting that renaming a remote with git remote rename also changes the names of its remote-tracking branches.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.