How to add Git remote
Adding a Git remote connects your local repository to a remote URL for pushing and pulling changes. As the creator of CoreUI with 26 years of development experience, I’ve configured Git remotes across hundreds of open-source and enterprise projects for collaboration and multi-environment deployments.
The fastest way is using git remote add.
Add a Remote
git remote add origin https://github.com/username/repo.git
This adds a remote named origin pointing to the GitHub repository.
Verify Remote Added
git remote -v
Output:
origin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)
Add Multiple Remotes
# Add origin (your fork)
git remote add origin https://github.com/your-username/repo.git
# Add upstream (original project)
git remote add upstream https://github.com/original-owner/repo.git
# Add staging server
git remote add staging https://git.staging.com/repo.git
# Add production server
git remote add production https://git.production.com/repo.git
# Verify all remotes
git remote -v
Push to Remote After Adding
# Add remote
git remote add origin https://github.com/username/repo.git
# Push main branch and set upstream
git push -u origin main
# Future pushes can use
git push
Add Remote with SSH
git remote add origin [email protected]:username/repo.git
SSH is preferred for authentication without passwords:
# Generate SSH key (if needed)
ssh-keygen -t ed25519 -C "[email protected]"
# Add to ssh-agent
ssh-add ~/.ssh/id_ed25519
# Add public key to GitHub settings
cat ~/.ssh/id_ed25519.pub
Fork Workflow Setup
# Clone your fork
git clone https://github.com/your-username/repo.git
cd repo
# Add upstream remote
git remote add upstream https://github.com/original-owner/repo.git
# Verify
git remote -v
# origin https://github.com/your-username/repo.git (fetch)
# origin https://github.com/your-username/repo.git (push)
# upstream https://github.com/original-owner/repo.git (fetch)
# upstream https://github.com/original-owner/repo.git (push)
# Fetch from upstream
git fetch upstream
# Merge upstream changes
git merge upstream/main
Add Remote for Existing Repository
If you created a local repo and want to connect it to remote:
# Initialize local repo
git init
git add .
git commit -m "Initial commit"
# Add remote
git remote add origin https://github.com/username/repo.git
# Push to remote
git push -u origin main
Error Handling
Remote Already Exists
git remote add origin https://github.com/username/repo.git
# fatal: remote origin already exists.
# Solution 1: Remove and re-add
git remote remove origin
git remote add origin https://github.com/username/repo.git
# Solution 2: Update URL
git remote set-url origin https://github.com/username/repo.git
Invalid URL
git remote add origin invalid-url
# fatal: 'invalid-url' does not appear to be a git repository
# Check URL is correct and accessible
curl -I https://github.com/username/repo.git
Best Practice Note
This is the Git remote configuration approach we use across all CoreUI repositories. Adding remotes enables collaboration, backup, and deployment workflows. Always use SSH for authenticated access, follow consistent naming conventions, and document your remote structure for team members. Use origin for your primary remote and upstream for the source project in fork workflows.
Related Articles
For more Git remote operations, check out how to change remote URL in Git and how to set upstream branch in Git.



