GitRemoving & Renaming Remotes

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

Bash
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 more git fetch <name>).

  • Does not delete commits — any commit reachable from a local branch stays.

  • Does not touch the server.

Renaming a remote

Bash
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)

Bash
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

Bash
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 origin or git fetch --prune) — keeps the remote but removes local pointers to branches that no longer exist on it.

Bash
# 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

Bash
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'
No undo
`git remote remove` is instantaneous and not reversible through Git. If you regret it, just re-add the remote: `git remote add origin <url>`. You may need to re-fetch to rebuild remote-tracking pointers.
Tip
Before you remove a remote, check whether it’s the only backup of any in-progress work. Run git log --branches --not --remotes to see commits that exist only locally. If those are important, push somewhere first.