How to Remove Upstream Repository in Git

Azhar Bashir Khan Feb 02, 2024
How to Remove Upstream Repository in Git

This tutorial will teach us how to remove the upstream repository in Git. We may sometimes require removing or changing the remote repositories used with our local repositories.

We can use the Git command git remote for such purposes.

Remove Upstream Repository in Git

We use Git in a collaborative development environment to keep track of the modifications done to the files in the project directory. The changes done to the files are tracked in the local Git repositories.

The local repositories, in turn, can be tracked with the remote Git repositories. The remote Git repositories are often hosted on remote servers on the Internet or network.

We can view the remote Git repository of our local repository by executing the Git command git remote as follows.

$ git remote -v
origin	https://github.com/johndoe/myrepo (fetch)
origin	https://github.com/johndoe/myrepo (push)

We typically clone from remote repositories. We can also add different remote repositories.

The remote repositories are called upstream because we fetch remote changes from those (i.e.) we download changes from the remote repositories. After modifications, we typically push the local changes upstream (i.e.) remote repositories.

We may sometimes require removing or changing the upstream remote repositories we previously had added. We can use the Git command git remote with the rm or remove option.

We can remove the upstream remote using the Git command git remote.

$ git remote remove upstream

We can then add a new upstream remote using the Git command git remote with the add option.

$ git remote add upstream https://github.com/johndoe/newrepo.git

We can also update the remote URL directly with the Git command git remote with the set-url option.

$ git remote set-url upstream https://github.com/johndoe/newrepo.git

Thus, we have learned how to remove the upstream repository in Git.

For more information, please visit:

  1. git-remote
  2. Git Basics - Working with Remotes

Related Article - Git Remote