How to Check, Change, and Delink a Remote Git Repository
How to Check, Change, and Delink a Remote Git Repository
When working with Git, it is common to migrate repositories between hosts (like GitHub, GitLab, or Bitbucket), fork an existing codebase, or start a project locally and need to switch remotes later.
Managing your repository's remote connections might sound intimidating, but it only takes a few straightforward terminal commands. Here is a practical, step-by-step guide to inspecting your current remote setup, changing it, or unlinking it entirely.
1. Check Your Current Git Repository Details
Before making changes, confirm the current state of your repository and where it points.
View Configured Remote URLs
To see the name and target URL of your remotes, run:
git remote -v
Example output:
origin https://github.com/username/old-repository.git (fetch) origin https://github.com/username/old-repository.git (push)
View Detailed Remote Information
If you want more context—such as tracked branches, push/pull URLs, and local tracking status—use:
git remote show origin
(Replace origin with the name of your remote if it uses a custom name.)
Check Local Git Configuration
To see all repository-level configuration parameters (including user credentials and branch configurations):
git config --local --list
2. Change the Remote URL
If your project moved to a new URL, username, or organization, you can update the remote directly rather than re-cloning the repository.
Option A: The Direct set-url Command (Recommended)
Use git remote set-url to update the destination URL:
git remote set-url origin https://github.com/username/new-repository.git
If you are switching to SSH:
git remote set-url origin git@github.com:username/new-repository.git
Option B: Rename the Remote
If you want to keep the old remote as a backup or reference (for instance, keeping an upstream repo while adding an origin fork), you can rename it:
# Rename 'origin' to 'upstream' git remote rename origin upstream # Add your new repository as the new 'origin' git remote add origin https://github.com/username/new-repository.git
Verify the Change
Always verify that your remote points to the new location:
git remote -v
3. Delink (Remove) the Remote
If you want to disconnect your local project from its remote repository entirely—without deleting your local files or local commit history—you can remove the remote connection.
Remove the Remote Connection
Run:
git remote remove origin
(or git remote rm origin in older Git versions)
Verify the Delink
Run:
git remote -v
If the command outputs nothing, your repository is completely delinked from any remote host. Your local commit history, staging area, and files remain untouched.
4. Resetting Completely (Nuclear Option: Un-Git a Project)
If your goal is not just to delink from a remote, but to remove Git tracking completely (so the folder becomes a regular, untracked directory), remove the hidden .git folder:
# On macOS / Linux / Git Bash rm -rf .git # On Windows (PowerShell) Remove-Item -Recurse -Force .git
Warning: This permanently deletes your entire local commit history, all stashes, and branch references. Only do this if you intend to start fresh from scratch.
To re-initialize as a brand new repository after this:
git init git add . git commit -m "Initial commit"
Quick Reference Summary
| Task | Command |
|---|---|
| Inspect remotes | git remote -v |
| Inspect details | git remote show <name> |
| Change remote URL | git remote set-url origin <new-url> |
| Rename remote | git remote rename <old-name> <new-name> |
| Delink remote | git remote remove origin |
| Add a new remote | git remote add origin <url> |