How to rename Git remote
Renaming a Git remote updates the local reference name while preserving the remote URL and tracking branches. As the creator of CoreUI with 26 years of development experience, I’ve managed Git remotes across hundreds of repositories where clear naming conventions improved team collaboration.
The fastest way is using git remote rename.
Rename a Remote
git remote rename origin upstream
This renames the remote from origin to upstream.
Verify the Rename
git remote -v
Output:
upstream https://github.com/user/repo.git (fetch)
upstream https://github.com/user/repo.git (push)
Common Use Case: Fork Workflow
When working with forks, rename origin to upstream and add your fork as origin:
# Clone the original repository
git clone https://github.com/original/repo.git
cd repo
# Rename original remote to upstream
git remote rename origin upstream
# Add your fork as origin
git remote add origin https://github.com/your-username/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/repo.git (fetch)
# upstream https://github.com/original/repo.git (push)
Update Tracking Branches
After renaming, update your local branches to track the renamed remote:
# Before rename
git branch -vv
# * main 1234567 [origin/main] Latest commit
# Rename remote
git remote rename origin upstream
# Update tracking
git branch -u upstream/main main
# Verify
git branch -vv
# * main 1234567 [upstream/main] Latest commit
Automatic Tracking Update
Git automatically updates tracking branches when you rename:
git remote rename origin upstream
# Tracking branches are automatically updated:
# origin/main → upstream/main
# origin/develop → upstream/develop
Rename Multiple Remotes
# List all remotes
git remote
# origin
# staging
# production
# Rename each
git remote rename origin github
git remote rename staging heroku-staging
git remote rename production heroku-prod
# Verify
git remote -v
# github https://github.com/user/repo.git (fetch)
# github https://github.com/user/repo.git (push)
# heroku-staging https://git.heroku.com/app-staging.git (fetch)
# heroku-staging https://git.heroku.com/app-staging.git (push)
# heroku-prod https://git.heroku.com/app-prod.git (fetch)
# heroku-prod https://git.heroku.com/app-prod.git (push)
What Happens When You Rename
When you rename a remote:
- Remote name changes - The local reference name is updated
- URL is preserved - The remote URL remains unchanged
- Tracking branches are updated -
origin/mainbecomesupstream/main - Git config is modified -
.git/configis updated with new name
Example .git/config change:
# Before
[remote "origin"]
url = https://github.com/user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
# After rename to upstream
[remote "upstream"]
url = https://github.com/user/repo.git
fetch = +refs/heads/*:refs/remotes/upstream/*
Error Handling
Remote Does Not Exist
git remote rename nonexistent newname
# error: Could not rename config section 'remote.nonexistent' to 'remote.newname'
# List available remotes first
git remote
Name Already Exists
git remote rename origin upstream
# error: remote upstream already exists.
# Remove the existing remote first
git remote remove upstream
git remote rename origin upstream
Push After Rename
After renaming, you can push to the renamed remote:
git remote rename origin github
# Push to renamed remote
git push github main
# Set upstream for current branch
git push -u github main
Fetch from Renamed Remote
git remote rename origin upstream
# Fetch from renamed remote
git fetch upstream
# Pull from renamed remote
git pull upstream main
Rename in Team Workflow
Each developer must rename independently:
# Developer 1
git remote rename origin company-github
# Developer 2 (on their machine)
git remote rename origin company-github
# Renaming is local and doesn't affect other team members
Script to Rename All Remotes
Create rename-remotes.sh:
#!/bin/bash
echo "Current remotes:"
git remote -v
read -p "Old remote name: " OLD_NAME
read -p "New remote name: " NEW_NAME
if git remote | grep -q "^$OLD_NAME$"; then
git remote rename "$OLD_NAME" "$NEW_NAME"
echo "✓ Remote renamed from '$OLD_NAME' to '$NEW_NAME'"
echo ""
echo "Updated remotes:"
git remote -v
else
echo "❌ Remote '$OLD_NAME' not found"
fi
Usage:
chmod +x rename-remotes.sh
./rename-remotes.sh
Rename vs Set-URL
Different operations:
# Rename: Change the remote name, keep URL
git remote rename origin upstream
# Set-URL: Change the URL, keep name
git remote set-url origin https://new-url.git
Check Remote Configuration
View remote details:
# Show remote names
git remote
# Show remote URLs
git remote -v
# Show detailed remote info
git remote show origin
# View in .git/config
cat .git/config | grep -A 2 "\[remote"
Undo Remote Rename
Rename it back:
# Original rename
git remote rename origin upstream
# Undo by renaming back
git remote rename upstream origin
# Verify
git remote -v
Best Practices
-
Use descriptive names:
git remote rename origin github-personal git remote rename upstream github-company -
Consistent naming across team:
# Standardize: origin = your fork, upstream = source git remote rename origin upstream git remote add origin https://github.com/your-fork/repo.git -
Document changes:
echo "Renamed origin to upstream on 2026-02-12" >> .git/RENAME_LOG -
Update documentation:
# Update README.md ## Development - Fork the repository - Clone your fork: `git clone <fork-url>` - Add upstream: `git remote add upstream <original-url>`
Multiple Remotes Pattern
Common multi-remote setup:
# Your fork
git remote add origin https://github.com/you/repo.git
# Original project
git remote add upstream https://github.com/original/repo.git
# Staging server
git remote add staging https://git.staging.com/repo.git
# Production server
git remote add production https://git.production.com/repo.git
# Verify all remotes
git remote -v
Rename with Different Fetch/Push URLs
If a remote has different fetch and push URLs:
git remote rename origin github
# Both fetch and push URLs are renamed
git remote -v
# github https://github.com/user/repo.git (fetch)
# github [email protected]:user/repo.git (push)
Best Practice Note
This is the Git remote naming strategy we use across all CoreUI repositories. Renaming remotes is a safe local operation that updates references while preserving URLs and connections. Use clear, descriptive names like github, gitlab, upstream, or company-repo to make multi-remote workflows more intuitive. Always communicate remote naming conventions with your team.
Related Articles
For more Git remote operations, check out how to add Git remote and how to remove Git remote.



