How to rename a remote in Git

Renaming a Git remote changes its local reference name without affecting the actual remote repository URL. As the creator of CoreUI with 26 years of development experience, I’ve renamed Git remotes across hundreds of repositories to maintain clear naming conventions and improve team workflow organization.

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 Rename

git remote -v

Output shows new name:

upstream  https://github.com/username/repo.git (fetch)
upstream  https://github.com/username/repo.git (push)

Common Rename Scenarios

Rename origin to upstream (fork workflow)

# You forked a project and want to track both
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-owner/repo.git (fetch)
# upstream  https://github.com/original-owner/repo.git (push)

Rename deployment remotes

# Rename staging to production
git remote rename staging production

# Rename heroku to old-heroku
git remote rename heroku old-heroku

# Add new heroku remote
git remote add heroku https://git.heroku.com/new-app.git

Standardize naming across projects

# Rename github to origin for consistency
git remote rename github origin

# Rename gitlab to mirror
git remote rename gitlab mirror

Update Tracking Branches After Rename

Remote tracking branches don’t automatically update:

# Rename remote
git remote rename origin upstream

# Your local branches still track old remote name
git branch -vv
# main                abc1234 [origin/main] Latest commit

# Update tracking branch
git branch --set-upstream-to=upstream/main main

# Or use shorter form
git branch -u upstream/main

Error Handling

Remote doesn’t exist

git remote rename nonexistent newname
# fatal: Could not rename config section 'remote.nonexistent' to 'remote.newname'

Check existing remotes:

git remote

New name already exists

git remote rename origin upstream
# fatal: remote upstream already exists

Either remove the existing remote first or choose a different name:

git remote remove upstream
git remote rename origin upstream

Batch Rename Script

Create rename-remote.sh:

#!/bin/bash

OLD_NAME=$1
NEW_NAME=$2

if [ -z "$OLD_NAME" ] || [ -z "$NEW_NAME" ]; then
  echo "Usage: ./rename-remote.sh <old-name> <new-name>"
  exit 1
fi

if ! git remote | grep -q "^$OLD_NAME$"; then
  echo "❌ Remote '$OLD_NAME' does not exist"
  exit 1
fi

if git remote | grep -q "^$NEW_NAME$"; then
  echo "❌ Remote '$NEW_NAME' already exists"
  exit 1
fi

git remote rename "$OLD_NAME" "$NEW_NAME"

if [ $? -eq 0 ]; then
  echo "✓ Renamed '$OLD_NAME' to '$NEW_NAME'"
  echo ""
  echo "Current remotes:"
  git remote -v
else
  echo "❌ Failed to rename remote"
  exit 1
fi

Usage:

chmod +x rename-remote.sh
./rename-remote.sh origin upstream

Best Practice Note

This is the Git remote naming convention we use across all CoreUI repositories. Rename remotes to maintain consistent naming: use origin for your primary repository, upstream for the source of forks, and descriptive names like staging or production for deployment targets. Document your remote naming conventions in team guidelines to ensure consistency across projects.

For more Git remote operations, check out how to add Git remote and how to remove a remote in Git.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author