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

Git remote Command

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

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.