How to Remove Remote Origin in Git

Abdul Jabbar Feb 02, 2024
  1. Remove a Remote Origin in Git
  2. Re-Adding a New Remote Origin in Git
  3. Best Way to Remove Remote Origin in Git
How to Remove Remote Origin in Git

When we have committed the wrong data to the origin, push it to the origin and merge it to the current branch. But then we realize that we don’t need that merge in that repository, so the question here is how to undo or revert a merge commit that is already pushed.

The remote name is the name of the remote server. It can be the name of a user account or a server name. The branch name can be the same as the local branch name or a different name. Remote means the remote repository, that is, the repository where the code is stored.

A Git remote is an object that stores information about another repository. It can be used to fetch or push to the other repository. A Git remote is used to create a new remote repository, add a new remote repository, remove the remote repository and list the remote repository.

It refers to the other repository copy that is usually provided on a remote server. In the standard workflow, a clone is done from the remote repository. A remote repository is generally named after the user who created it. A remote repository can have one or more remotes origins.

The repository that is referred to by your remote is called the origin. Every repository has a default remote. You can check the default remote for your repository by running:

git remote -v

The above command will return a name as this remote is named origin since it originates from the cloned repository.

Remove a Remote Origin in Git

This article will discuss how to remove a Git origin remote repository. To remove a remote origin, we will need to remove its reference in our local repository. But be careful when removing a remote origin since this will delete the remote origin and all its data from our local repository.

Once it is deleted successfully, we will not push it to that remote repository anymore. To remove a Git remote origin, run the following command.

git remote rm <remote> 

Here <remote>is the name of the remote origin we want to remove.

For instance, to remove the remote origin:

git remote rm origin

To list all remotes origin, we will run the following command:

git remote -v

Re-Adding a New Remote Origin in Git

After removing a remote origin, we can add it again through the following command:

git remote add origin your_Remote_Url

then execute:

git push -u origin master

Best Way to Remove Remote Origin in Git

The easiest way to remove the remote origin and add a new one through a single command is mentioned below:

git remote set-url origin newUrl 
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Remote