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

How to remove a remote 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.


Sometimes, you may need to remove a Git remote for various reasons, such as renaming, transferring ownership, or cleaning up old references. This guide covers various commands related to removing remotes and their branches, including git remove remote, git remove remote branch, and more.

Before diving into how to remove a remote, it's essential to understand what a "remote" is in the context of Git. A remote in Git refers to a version of your repository that is hosted on the internet or a local network, allowing you to push to and pull from it. Typically, origin is the default name given to the remote that points to the original repository you cloned from.

For a deeper explanation, see this guide on Git remotes.

To remove a remote from your local repository, you can use the git remote remove command. Here's how you do it:

  1. Open your terminal.
  2. Navigate to your local Git repository.
  3. Run the following command:
Terminal
git remote remove <remote_name>

Replace <remote_name> with the name of the remote you wish to remove, such as origin.

If you want to remove the remote named origin, you can run:

Terminal
git remote remove origin

This command updates the local configuration settings by removing the section related to origin.

Removing a remote branch involves deleting the branch from the remote repository. To do this, you use the git push command with the --delete flag. Here's how:

  1. Ensure you have the latest information of your branches with git fetch.
  2. To delete the remote branch, use:
Terminal
git push <remote_name> --delete <branch_name>

Replace <remote_name> with the name of the remote (e.g., origin) and <branch_name> with the name of the branch you want to remove.

Terminal
git push origin --delete feature_branch

This command will delete the feature_branch from the origin remote.

For more information, see this guide on deleting Git branches.

Sometimes, you might want to clean up both your local and remote branches:

  1. Delete the remote branch as described above.
  2. Delete the local branch by running:
Terminal
git branch -d <branch_name>

Replace <branch_name> with the name of your local branch. Use -D instead of -d if the branch is not yet fully merged.

Tags, once pushed to a remote, can also be removed:

Terminal
git push <remote_name> --delete tag <tag_name>

Replace <tag_name> with the name of the tag you wish to remove.

Removing remotes, branches, and tags in Git is a powerful way to manage your repository's history. Whether you're renaming a remote, cleaning up old branches, or deleting tags, these commands provide you with the control you need to maintain a clean Git repository.

If you want to fully delete your remote because you're concerned about a potential leak of confidential information, see this guide on deleting sensitive data in Git.

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