How to remove remote origin from a Git repository
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Removing origin from a Git repository means deleting the local configuration entry that points to that remote server. It does not delete your commits, branches, or the remote repository itself. It only removes the connection information stored in your local .git/config.
The Command
The standard command is:
The shorter alias is equivalent:
Afterward, verify the change:
If origin was the only remote, the command prints nothing.
What origin Actually Is
origin is just a conventional remote name, not a special Git keyword. Most clones start with a remote named origin, but Git would work the same if it were named github, primary, or anything else.
That means removing origin deletes one named remote, not some global repository concept.
What Changes After Removal
When you remove a remote:
- the
originentry is removed from.git/config - fetch and push URLs for that remote are deleted
- remote-tracking references such as
origin/mainare removed - local branches remain intact
- local commits remain intact
Your repository history is still there. You simply no longer have a configured destination called origin.
A Practical Example
Check the current remotes first.
Sample output:
Now remove origin.
If you run git remote -v again, only upstream remains.
When to Remove Instead of Changing the URL
If you are just correcting the address for the same logical remote, set-url is often better than removing and re-adding.
Use remove when:
- the remote is no longer relevant
- you want a clean reconfiguration
- you accidentally added the wrong remote name entirely
- you are disconnecting a cloned repository before attaching a different remote
Re-Add a New origin
After removing the old remote, you can add a new one.
Then push and recreate upstream tracking if needed.
That -u flag records the upstream relationship again for the current branch.
Inspecting the Underlying Config
If you want to see what Git is changing, look at .git/config before and after.
Removing the remote deletes entries like:
- '
remote.origin.url' - '
remote.origin.fetch'
This can be useful when debugging odd remote state.
Related Operations
Rename a remote instead of removing it:
Show one remote's details:
Get the remote URL directly:
These commands help you decide whether removal is actually what you want.
Common Pitfalls
A common mistake is thinking remote removal deletes the repository on GitHub, GitLab, or another host. It does not. It changes only local Git configuration.
Another mistake is removing origin when the real goal was just to update the URL. In that case, git remote set-url is usually cleaner.
Developers also sometimes forget that after replacing a remote, local branches may need their upstream tracking reset with git push -u or git branch --set-upstream-to.
Summary
- Remove the remote with
git remote remove origin. - This deletes only the local remote configuration, not your commits or the hosted repository.
- Use
git remote -vto verify the result. - If you only need a new URL,
git remote set-url origin ...is often better. - Re-add a new
originand restore upstream tracking if you plan to keep pushing.

