Removing & Renaming Remotes
Remotes are just labels in your local Git config — adding, removing, and renaming them is fast and completely safe (the actual server is untouched). You’ll do this when a remote URL changes, when you’re cleaning up an old setup, or when you reorganise multiple remotes.
Removing a remote
git remote remove <name> # Or the shorter alias: git remote rm <name> # Example: git remote remove old-upstream
Removes the entry from
.git/config.Deletes the corresponding
refs/remotes/<name>/*pointers (no moregit fetch <name>).Does not delete commits — any commit reachable from a local branch stays.
Does not touch the server.
Renaming a remote
git remote rename <old-name> <new-name> # Example: rename origin to github git remote rename origin github
Renaming updates every reference: tracking branches like origin/main move to github/main, and git push / git pull upstream config follows along.
Changing a remote’s URL (without removing/re-adding)
git remote set-url origin git@github.com:user/repo.git # Different URL for fetch vs push git remote set-url --push origin git@private-server:user/repo.git # To see the current URLs: git remote -v
Common reasons to remove a remote
The remote moved to a different host (GitHub → GitLab). Either remove and re-add, or just
set-url.A fork was deleted and you no longer need its
upstream.A deployment target was decommissioned.
You cloned via HTTPS and want to switch the whole repo to SSH.
What happens to local branches?
Local branches that tracked the removed remote (e.g., main tracking origin/main) lose their upstream. The local branch itself is fine — but git push and git pull with no arguments may complain until you set a new upstream.
Fix the tracking
git branch --unset-upstream # Then re-set when you add a new remote git push -u newremote main
Pruning vs removing
Remove — deletes the remote itself. Stops using it entirely.
Prune (
git remote prune originorgit fetch --prune) — keeps the remote but removes local pointers to branches that no longer exist on it.
# Stale remote branches piling up? git fetch --prune # Or set as default git config --global fetch.prune true
Inspecting before removing
See if any local branch still tracks the remote
git branch -vv | grep origin # * main 1f9ab2c [origin/main] ... # feature-x d4b1e0c [origin/feature-x: ahead 1] ... # These local branches will lose their upstream after 'remote remove origin'
git log --branches --not --remotes to see commits that exist only locally. If those are important, push somewhere first.