How to remove Git remote

Removing a Git remote disconnects your local repository from a remote URL, useful when changing hosting providers or cleaning up old connections. As the creator of CoreUI with 26 years of development experience, I’ve managed Git remotes across hundreds of open-source and enterprise projects.

The fastest way is using git remote remove or its alias git remote rm.

Remove a Remote

git remote remove origin

Or using the shorter alias:

git remote rm origin

Verify Removal

Check that the remote was removed:

git remote -v

Remove Specific Remote

If you have multiple remotes:

# List all remotes
git remote -v

# Output:
# origin    https://github.com/user/repo.git (fetch)
# origin    https://github.com/user/repo.git (push)
# upstream  https://github.com/original/repo.git (fetch)
# upstream  https://github.com/original/repo.git (push)

# Remove specific remote
git remote remove upstream

Common Use Cases

Switching Git Hosting Providers

# Remove old remote
git remote remove origin

# Add new remote
git remote add origin https://gitlab.com/user/repo.git

# Verify
git remote -v

# Push to new remote
git push -u origin main

Cleaning Up After Fork

# Remove upstream remote after finishing contribution
git remote remove upstream

# Keep only your fork
git remote -v
# origin    https://github.com/your-username/repo.git (fetch)
# origin    https://github.com/your-username/repo.git (push)

Fixing Wrong Remote URL

Instead of removing and re-adding, you can update the URL:

# Option 1: Update existing remote URL
git remote set-url origin https://github.com/new-url/repo.git

# Option 2: Remove and re-add
git remote remove origin
git remote add origin https://github.com/new-url/repo.git

Remove All Remotes

# List all remote names
git remote

# Remove each remote
for remote in $(git remote); do
  git remote remove $remote
done

# Verify all removed
git remote -v

What Happens When You Remove a Remote

When you remove a remote:

  1. Local branches are preserved - Your local work is not affected
  2. Remote-tracking branches are removed - References like origin/main are deleted
  3. Remote configuration is deleted - URL and fetch refspecs are removed from .git/config
  4. You can no longer push/pull - Until you add a new remote

Example:

# Before removal
git branch -a
# * main
#   remotes/origin/main
#   remotes/origin/develop

git remote remove origin

# After removal
git branch -a
# * main

# Remote-tracking branches are gone

Remove Remote vs Remove Remote Branch

Different operations:

# Remove the entire remote connection
git remote remove origin

# Remove a specific remote branch (keeps remote connection)
git push origin --delete feature-branch

Error Handling

Remote Does Not Exist

git remote remove nonexistent
# error: No such remote: 'nonexistent'

# List available remotes first
git remote

Cannot Remove Remote You’re Tracking

If you try to remove a remote while on a tracking branch:

# You're on main tracking origin/main
git branch -vv
# * main 1234567 [origin/main] Latest commit

# Remove remote
git remote remove origin
# Warning: remote-tracking branch references removed

# Your local branch remains but no longer tracks remote
git branch -vv
# * main 1234567 Latest commit

Restore Remote-Tracking Branches

If you removed a remote by mistake:

# Re-add the remote
git remote add origin https://github.com/user/repo.git

# Fetch to restore remote-tracking branches
git fetch origin

# Set upstream for current branch
git branch --set-upstream-to=origin/main main

Check Remote Configuration

View remote details before removing:

# Show remote URLs
git remote -v

# Show detailed remote configuration
git remote show origin

# Check .git/config
cat .git/config | grep -A 3 "\[remote"

Remove Remote from .git/config

Alternatively, you can manually edit .git/config:

# Before
[remote "origin"]
    url = https://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

# After (delete the entire [remote "origin"] section)

Then verify:

git remote -v
# (empty output)

Best Practices

  1. Always verify before removing:

    git remote -v
    git remote remove origin
    git remote -v
    
  2. Push important work first:

    git push origin main
    git remote remove origin
    
  3. Document remote changes:

    echo "Changed remote from GitHub to GitLab on 2026-02-11" >> CHANGELOG.md
    git commit -am "docs: Update remote configuration"
    
  4. Use set-url when changing URLs:

    # Preferred over remove + add
    git remote set-url origin https://new-url.git
    

Script to Safely Remove Remote

Create remove-remote.sh:

#!/bin/bash

REMOTE_NAME=${1:-origin}

echo "Current remotes:"
git remote -v

read -p "Remove remote '$REMOTE_NAME'? (y/n) " -n 1 -r
echo

if [[ $REPLY =~ ^[Yy]$ ]]; then
  git remote remove "$REMOTE_NAME"
  echo "✓ Remote '$REMOTE_NAME' removed"
  echo "Updated remotes:"
  git remote -v
else
  echo "Cancelled"
fi

Usage:

chmod +x remove-remote.sh
./remove-remote.sh origin

Best Practice Note

This is the Git remote management approach we use across all CoreUI repositories. Removing remotes is a safe local operation that only affects your repository’s configuration. Always verify your remote connections with git remote -v and ensure important work is pushed before removing remotes. Use git remote set-url when you only need to change the URL rather than completely removing the remote.

For more Git remote operations, check out how to add Git remote and how to rename Git remote.


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

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.

Answers by CoreUI Core Team