Data report"State of code review 2024" is now liveRead the full report

How to remove a remote origin in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Removing a remote origin in Git disconnects your local repository from a specific remote repository URL. This could be due to a change in the remote server, a migration to another repository, or simply to correct a mistake in the URL.

In Git, a 'remote' refers to a version of your repository that is hosted on the internet or some other network. 'Origin' refers to the remote repository that your local repository was cloned from. Git tracks these remotes with URLs linked to the remote repositories. Remote repositories allow you to push and pull changes to and from other developers involved in the project.

Here are a few scenarios where you might need to remove a remote origin:

  • Repository migration: The original repository might be moved to a different host or URL.
  • URL correction: Incorrect URL setup needs correction.
  • Project restructuring: Sometimes, project restructuring might require reorganizing the remotes.

Here are detailed steps and examples on how to remove a remote origin from your Git repository:

Before making any changes, it's a good practice to view all configured remotes to confirm the name and URLs associated with them. This can prevent any unintended removals. You can check your current remotes with:

Terminal
git remote -v

This command will list all remotes along with the URLs. For example, you might see something like this:

Terminal
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
  • origin: This is the default name Git gives to your remote repository. "Origin" is a shorthand name for the remote repository that a project was originally cloned from. More remote repositories can be added with different names.

  • https://github.com/user/repo.git: This URL is the address where the remote repository is located. It is used by Git to fetch (pull down code) and push (upload code) changes. The URL format can vary based on how the repository is accessed; it might use HTTPS (as in this example) or SSH (e.g., git@github.com:user/repo.git).

  • (fetch): This label indicates that the URL next to it is used for fetching data from the remote repository. Fetch operations include downloading objects and refs from another repository.

  • (push): This label shows that the URL next to it is used for pushing data to the remote repository. Push operations include uploading objects and refs to another repository.

The output shows each remote's name followed by the URLs for fetching and pushing, respectively. If a remote has the same URL for both fetch and push, it will appear twice in the output as shown. This distinction is important because it's possible (though less common) to have different URLs configured for fetching and pushing to the same remote repository.

To remove a remote, you use the git remote remove command followed by the name of the remote, which is often 'origin':

Terminal
git remote rm origin

This command deletes the link to the remote repository named 'origin'. After executing this command, if you run git remote -v again, you'll see that the origin is no longer listed.

It's important to ensure that the remote has been successfully removed:

Terminal
git remote -v

If the removal was successful, this command should not list the remote you just deleted. If it's still there, ensure the command was entered correctly and that you're in the proper directory.

If you need to add a new remote origin, you can easily do so using the following command:

Terminal
git remote add origin new-url.git

Replace new-url.git with the actual URL of your new remote repository. This sets up a new remote named 'origin' linked to the specified URL.

  • Permission errors: Ensure you have the necessary permissions to modify the remote settings if you're working in a shared repository.
  • Network issues: Problems like timeouts or server unavailability can impede your ability to modify remote settings. Check your network connection if you encounter such issues.

For further reading on Git remotes, see the official Git documentation.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2