Skip to main content
Infrastructure as Code (IaC) Cheat Sheets

git remote rm Command Reference: Remove Remote Repositories

git remote rm removes a tracked remote reference from .git/config. Syntax: git remote rm <remote-name> (alias: git remote remove).

git remote rm <remote-name>
# or
git remote remove <remote-name>

Options and Flags

Flag Type Default Description
-v, –verbose flag N/A Show verbose output when listing remotes (used before removal to verify). Not used directly with rm.
<remote-name> argument required Name of the remote to remove (e.g., origin, upstream). Must exist in local config.

Usage Examples

1. Remove the default remote ‘origin’

git remote rm origin
# Verify removal
git remote -v
# No output indicates success

Use this after finishing work with a remote repository or to reconfigure for a different remote. The operation is irreversible except by re-adding the remote.

2. List remotes before removal

git remote -v
# Output:
# origin  git@github.com:user/repo.git (fetch)
# origin  git@github.com:user/repo.git (push)
git remote rm origin

Always verify remote names with -v before removal to avoid removing the wrong remote, especially in repos with multiple remotes (e.g., origin, upstream, staging).

See also  Git Squash Commits: Syntax, Flags, Examples & Troubleshooting

3. Remove a remote after renaming

git remote -v
# origin -> https://github.com/OWNER/REPOSITORY.git
git remote rename origin destination
git remote rm destination
# Config section removed

This pattern helps avoid the “remote origin already exists” error when adding a new remote. Rename before removing to preserve a reference if needed.

4. Remove a remote that doesn’t exist (error handling)

git remote rm nonexistent
# Output: fatal: No such remote 'nonexistent'
# Exit code 1

A common mistake when the remote name is misspelled or already removed. Verify with git remote -v first.

Troubleshooting & Common Errors

Error Message/Code Root Cause Resolution Command
fatal: No such remote '<name>' Remote name does not exist in local config.
git remote -v   # list existing remotes
git remote rm <correct-name>
error: Could not remove config section 'remote.<name>' Git could not delete the section from .git/config (permissions or corruption).
# Manually edit .git/config to remove the section
# Or check file permissions: ls -la .git/config
fatal: remote origin already exists Attempting to add a remote with a name already present.
git remote rm origin   # then re-add
# Or rename: git remote rename origin <new-name>

Closing Tip

Always run git remote -v before git remote rm to confirm the remote name. Removal is irreversible — re-adding requires the full URL.

Frequently Asked Questions

What is the difference between git remote rm and git remote remove?

Answer: None – they are exact aliases. Both are identical in Git source code. Use whichever you prefer; there is no functional difference.

git remote rm origin   # removes remote named 'origin'
git remote remove origin   # identical to above

When should I use git remote remove instead of git remote prune?

Answer: Use remove to permanently delete a remote. git remote remove deletes the remote URL and all remote-tracking branches. git remote prune origin removes local references to branches that no longer exist on the remote but keeps the remote itself.

git remote remove deprecated-server   # removes remote entirely
git remote prune origin               # cleans stale branch references only

How do I fix error “fatal: No such remote: ‘upstream'” when removing a remote?

Answer: Verify the remote name with git remote -v. This error occurs when the remote name doesn’t exist in .git/config. To confirm:

git remote -v
# if 'upstream' is listed, re-run: git remote remove upstream
# if not, the remote was already deleted – no action needed

Common causes: typo, whitespace, or removal by another process. Use cat .git/config to inspect remote entries.

See also  Ansible Hosts File: Syntax, Examples, Flags & Production Guide

Does git remote remove work on all platforms (Linux, macOS, Windows, cloud CI runners)?

Answer: Yes – it is a core Git command available in Git ≥1. It manipulates the local repo’s .git/config file, which is POSIX-compliant. Runs without modification on GitHub Actions, GitLab CI, Jenkins, and Azure Pipelines. Windows users: avoid backslashes in remote names – forward slashes are universal.

# Example: removing a remote in a CI job
git remote remove deployment-server

What is the fastest way to remove multiple remotes in Git?

Answer: Use a shell loop: for r in remote1 remote2; do git remote remove "$r"; done. To remove all remotes except a specific one:

for r in $(git remote | grep -v keep-this); do git remote remove "$r"; done

Always test with echo first.