Remove the origin remote from a Git repository

Delete a local remote configuration, retain wanted commits first, or change the URL without removing the remote.

Best practices
Illustration of Git branches and version history

Run git remote remove origin to remove that remote from your local repository. It removes associated remote-tracking refs and configuration; it does not delete the server repository or rewrite your local branches and working files.

Inspect, preserve, and remove

git remote -v
git branch -r
git branch -vv

Record the URL and any custom fetch or push configuration you need. If a wanted commit is reachable only through a remote-tracking ref, create a local branch before removing that ref:

git branch saved-feature origin/feature
# After checking what should be retained:
git remote remove origin
git remote -v

Use an actual source ref and an unused local branch name. Other remotes can still appear in the final listing. git remote rm origin is an equivalent spelling.

Change an address without removing the remote

If the repository simply moved, this is usually the more direct operation:

git remote set-url origin https://git.example.com/team/repo.git

Review separate push URLs or multiple URLs if the remote has them. Changing the ordinary URL does not necessarily replace every customized destination.

To add a remote after removal, use git remote add origin URL, then fetch and inspect its refs. A reviewed git push -u origin main can publish a selected branch and configure its upstream; do not assume the new destination already contains the same history.

Related operations

Intent Command
Remove a local remote entry git remote remove origin
Change its URL git remote set-url origin URL
Rename the remote git remote rename origin upstream
Add another remote git remote add upstream URL

A fork workflow often keeps both the fork and upstream repository under separate remote names. Remove only the entry you no longer need. Each clone has its own configuration, so this operation does not alter collaborators' remote settings.

Tracking and recovery

Removing the remote cleans up associated tracking configuration and refs. Re-adding the same name does not reconstruct every previous refspec or upstream setting. After fetching, inspect git branch -vv; if appropriate, restore tracking with git branch --set-upstream-to=origin/main main.

The remote URL is configuration, not a versioned Git object. Recover it from a saved configuration, previous terminal output, or another reliable record, then add it again. Commits that lost their last protecting ref may eventually be removed by object cleanup, which is why preserving important remote-only history first matters.

See git-remote and branch upstream configuration.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting