git remote
Manage connections to remote repositories
Practical Example
git remote -v # origin https://github.com/user/repo.git (fetch) # origin https://github.com/user/repo.git (push) git remote add upstream https://github.com/original/repo.git
Command Overview & How It Works
Remotes are shorthand names for URLs to hosted repositories. The default remote after cloning is 'origin', which points to the URL you cloned from. Use git remote -v to list all remotes with their fetch and push URLs (they can be different). Use git remote add <name> <url> to connect a new remote, git remote remove <name> to delete one, and git remote rename <old> <new> to rename. Use git remote set-url <name> <new-url> to change a remote's URL without removing and re-adding it. Use git remote show <name> to see detailed information about a remote's branches, tracking relationships, and whether it is reachable. Multiple remotes are common when working with forks — origin points to your fork, upstream points to the original repository.
Practical Tips
- •Use git remote -v to see both fetch and push URLs — they can point to different addresses.
- •In a fork workflow, keep origin pointing at your fork and add the original project as upstream: git remote add upstream <url>.
- •Change a remote's URL with git remote set-url origin <new-url> instead of deleting and re-adding it.