Git
Repository Management
Remote Origin
Command Line Tools
Git Commands

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:

bash
git remote remove origin

The shorter alias is equivalent:

bash
git remote rm origin

Afterward, verify the change:

bash
git remote -v

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 origin entry is removed from .git/config
  • fetch and push URLs for that remote are deleted
  • remote-tracking references such as origin/main are 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.

bash
git remote -v

Sample output:

text
1origin  [email protected]:alice/project.git (fetch)
2origin  [email protected]:alice/project.git (push)
3upstream  [email protected]:team/project.git (fetch)
4upstream  [email protected]:team/project.git (push)

Now remove origin.

bash
git remote 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.

bash
git remote set-url origin [email protected]:alice/new-project.git

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.

bash
git remote add origin [email protected]:alice/new-project.git

Then push and recreate upstream tracking if needed.

bash
git push -u origin main

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.

bash
git config --get-regexp '^remote\.'

Removing the remote deletes entries like:

  • 'remote.origin.url'
  • 'remote.origin.fetch'

This can be useful when debugging odd remote state.

Rename a remote instead of removing it:

bash
git remote rename origin old-origin

Show one remote's details:

bash
git remote show origin

Get the remote URL directly:

bash
git remote get-url origin

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 -v to verify the result.
  • If you only need a new URL, git remote set-url origin ... is often better.
  • Re-add a new origin and restore upstream tracking if you plan to keep pushing.

Course illustration
Course illustration

All Rights Reserved.