How to remove a remote in Git

Removing a Git remote disconnects your local repository from a remote URL, useful for cleaning up unused remotes or changing repository configuration. As the creator of CoreUI with 26 years of development experience, I’ve managed Git remotes across hundreds of repositories, removing outdated deployment targets and reorganizing remote configurations for optimal workflows.

The fastest way is using git remote remove.

Remove a Remote

git remote remove origin

This removes the remote named origin from your local repository.

Alternative command:

git remote rm origin

Both commands do the same thing.

Verify Remote Removed

git remote -v

The removed remote should no longer appear in the list.

Remove Multiple Remotes

# Remove origin
git remote remove origin

# Remove upstream
git remote remove upstream

# Remove staging
git remote remove staging

# Verify all removed
git remote -v

Remove and Re-add Remote

# Remove existing remote
git remote remove origin

# Add new remote with correct URL
git remote add origin https://github.com/username/new-repo.git

# Verify
git remote -v

Common Use Cases

Remove Outdated Deployment Remote

# List current remotes
git remote -v
# origin    https://github.com/user/repo.git (fetch)
# origin    https://github.com/user/repo.git (push)
# heroku    https://git.heroku.com/old-app.git (fetch)
# heroku    https://git.heroku.com/old-app.git (push)

# Remove old Heroku remote
git remote remove heroku

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

Clean Up After Fork Workflow

# You no longer need upstream after merging your PR
git remote remove upstream

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

Switch from HTTPS to SSH

# Remove HTTPS remote
git remote remove origin

# Add SSH remote
git remote add origin [email protected]:username/repo.git

# Verify
git remote -v
# origin  [email protected]:username/repo.git (fetch)
# origin  [email protected]:username/repo.git (push)

Error Handling

Remote Doesn’t Exist

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

Check existing remotes first:

git remote

Remote Has Tracking Branches

Removing a remote doesn’t delete local tracking branches:

# Remove remote
git remote remove origin

# Delete tracking branches manually
git branch -r
# origin/main
# origin/feature-branch

# Delete remote tracking branches
git branch -d -r origin/main
git branch -d -r origin/feature-branch

Remove All Remotes

# Get list of all remotes
git remote | while read remote; do
  git remote remove "$remote"
done

# Verify all removed
git remote -v

Remove Remote vs Change URL

Don’t remove if you just want to change URL:

# Instead of:
git remote remove origin
git remote add origin https://new-url.git

# Do this:
git remote set-url origin https://new-url.git

Best Practice Note

This is the Git remote cleanup approach we use across CoreUI repositories when reorganizing deployment pipelines or changing hosting providers. Remove remotes instead of leaving them configured to avoid accidentally pushing to wrong targets. Always verify with git remote -v after removing remotes, and document remote changes in team communication channels.

For more Git remote operations, check out how to add Git remote and how to rename 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

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Bootstrap 6: Everything You Need to Know (And Why CoreUI Is Already Ahead)
Bootstrap 6: Everything You Need to Know (And Why CoreUI Is Already Ahead)

How to convert a string to boolean in JavaScript
How to convert a string to boolean in JavaScript

JavaScript printf equivalent
JavaScript printf equivalent

How to sleep in Javascript
How to sleep in Javascript

Answers by CoreUI Core Team