How To Remove Git Remote Repository

Related Content

In this article, we’ll continue the Linux how-to series and guide you on how to remove a Git remote repository. We’ll cover the difference between local and remote repositories and two possible workflows for Git remote repository. Take a look at our infographics to learn everything in less than one minute!

What is Git

Git is a free, open-source, and popular version control system that is used for tracking changes in computer files and coordinating work on those files among multiple people. Git is most commonly used for software development, but it can be used to track changes in any set of files. Git tracks changes to a file by storing a copy of the file at each stage of its development. This allows developers to easily go back and forth between different versions of a file, as well as see who made which changes and when. Git also makes it easy to share files among developers, as well as keep track of which version of a file is the most up-to-date. In short, Git is an extremely powerful tool that can be used for a wide variety of purposes.

Local Git Repository

Git is a decentralized distributed version control system. That means that you can store your software code changes on your local PC or remote server. Software changes that you keep locally form the local repository.

Local repository developer workflow

To create (or initiate) a local repository, you’re using the following command:

$ git init

To add and commit your changes to your local Git repository, use:

$ git add

$ git commit

Remote Git Repository

To simplify the software development process for distributed teams, people started to use a dedicated server as a central place for code exchange. A Git repository at such a server is called a remote repository. Nowadays, we have several Git hosting services, such as Bitbucket, Github, or GitLab.

Here’s the most straightforward workflow with one remote repository:

Local and single remote repository for development workflow

We can add information about the remote Git repository to our local repository using the following command:

$ git remote add origin git-remote-url

Where:

  • origin – is the logical name or remote repository; the origin is the default name for the remote repository.
  • git-remote-url – is the URL of the remote repository; usually, you’re getting it at your repository page at GitHub.

Cloning a Git repository from a remote server creates the origin automatically at your local repository.

For the case of a distributed team using the same remote repository, here’s another diagram:

Developers collaboration (workflow) using single remote repository

In the open-source world, team workflow is a bit different. A distributed team is not pushing code changes directly to a single repository, but they send pull requests. Using pull requests instead of committing directly to a single repository is a more efficient way to control changes coming to it.

To not overcomplicate the diagram, we’ll show only one developer workflow, working with his remote origin and sending pull requests to the upstream repository.

Two remote Git repositories

Removing a Git Remote URL

Before deleting any records of remote Git repositories, it makes sense to list them first:

$ git remote -v
git remote - command

To remove a Git remote repository, use the following command:

# Original command

$ git remote rm origin

# Alternative syntax

$ git remote remove origin

This command will remove an origin (usually, your default Git remote repository) from the remote list:

git remote rm origin - command

Note: the git remote remove command is just an alternative syntax (alias) for the git remote rm command.

The git remote rm command allows you to delete a remote repository reference from the .git/config file located in your project folder.

Attention: The most common mistake while removing remote Git repository is typing the git remove remote command in your shell instead of using correct commands such as git remote rm and git remote remove.

A rule of thumb to remember a correct command syntax: you’re asking git to manage remote repository, and you’re willing to remove it.

A git remote set of commands allows you to manage remote URLs for Git repositories.

Another way to remove the remote repository is to edit the .git/config file, but this method is not the most widely used.

If you’re trying to remove a remote repository that does not exist, Git throws an error.

$ git remote rm origin

The output is fatal: No such remote: 'origin':

git remote rm origin -  failed command

Usually, the above error can also be caused by mistyping the remote repository name.

The git remote rm command has an alias git remote remove, which works in the same way:

$ git remote remove git-repository-logical-name

The example above allows you to remove a particular remote repository, just use the remote name of your remote repository instead of git-repository-logical-name.

Summary

In this article, you’ve learned how to remove information about the remote Git repository from our local repository.

If you have any questions, please, feel free to reach out in the comments section below.

LIKE THIS ARTICLE?
Facebook
Twitter
LinkedIn
Pinterest
WANT TO BE AN AUTHOR OF ANOTHER POST?

We’re looking for skilled technical authors for our blog!

Table of Contents