How to add a remote in Git
Adding Git remotes allows you to track multiple repositories, sync with upstream projects, and manage forks effectively. As the creator of CoreUI with 25 years of Git experience managing open-source projects with thousands of contributors, I regularly use multiple remotes for collaboration workflows.
The most common command is git remote add <name> <url> to add a new remote repository.
Direct Answer
Add a remote with a name and URL:
git remote add upstream https://github.com/original/repo.git
View Existing Remotes
Check current remotes:
git remote -v
Output:
origin https://github.com/you/repo.git (fetch)
origin https://github.com/you/repo.git (push)
Add Upstream Remote
For forked repositories, add the original:
git remote add upstream https://github.com/original/repo.git
Verify:
git remote -v
Output:
origin https://github.com/you/repo.git (fetch)
origin https://github.com/you/repo.git (push)
upstream https://github.com/original/repo.git (fetch)
upstream https://github.com/original/repo.git (push)
Fetch from Upstream
Pull latest changes from upstream:
git fetch upstream
git merge upstream/main
Or rebase:
git fetch upstream
git rebase upstream/main
Add Multiple Remotes
Add collaborator’s fork:
git remote add alice https://github.com/alice/repo.git
git remote add bob https://github.com/bob/repo.git
Fetch from specific remote:
git fetch alice
git checkout -b alice-feature alice/feature-branch
Add Remote with SSH
Use SSH instead of HTTPS:
git remote add origin [email protected]:user/repo.git
Push to Specific Remote
Push to non-origin remote:
git push upstream main
Set Default Push Remote
Configure default push for a branch:
git push -u upstream main
Now git push defaults to upstream.
Remove Remote
Delete a remote:
git remote remove alice
Or use rm:
git remote rm bob
Rename Remote
Change remote name:
git remote rename origin old-origin
git remote rename new-origin origin
Sync Fork Workflow
Complete fork sync workflow:
# Add upstream
git remote add upstream https://github.com/original/repo.git
# Fetch upstream changes
git fetch upstream
# Merge into main
git checkout main
git merge upstream/main
# Push to your fork
git push origin main
Check Remote Details
View remote URL and branches:
git remote show upstream
Output:
* remote upstream
Fetch URL: https://github.com/original/repo.git
Push URL: https://github.com/original/repo.git
HEAD branch: main
Remote branches:
main tracked
develop tracked
Best Practice Note
This is the same remote management workflow we use in CoreUI’s open-source repositories. The origin remote is your fork, while upstream tracks the original project. This allows you to sync with the main repository while maintaining your own fork for pull requests.
Related Articles
For related Git operations, check out how to change remote URL in Git and how to set upstream branch in Git.



