Find the Original Git Clone URL of a Local Repository
Locate the original Git clone URL for a local repo. Run git remote -v or git remote get-url, or view .git/config to find origin, upstream, and GitHub parent.
How to determine the original clone URL of a local Git repository
I’ve cloned a project with multiple GitHub forks but can’t remember which specific fork I pulled from. What Git commands or methods can I use to identify the original remote repository URL and determine which fork I’m working with?
To determine the Git original clone URL of a local Git repository, run git remote -v in the repo root — the remote repository you cloned from is usually named origin and both fetch/push URLs will be shown. For a single-line URL use git config --get remote.origin.url or git remote get-url origin, or open the .git/config file to read [remote "origin"]. If there are multiple GitHub forks, check for an upstream remote or open the remote URL on GitHub (or query the GitHub API) to see which fork is the parent.
Contents
- Use git remote -v to find the original clone URL
- Use git config or inspect .git/config for the clone URL
- Identify the GitHub fork: origin vs upstream
- When remotes were changed or removed — what you can (and can’t) recover
- Quick checklist and commands to run now
- Sources
- Conclusion
Use git remote -v to find the original clone URL
Start here — it’s fast and usually all you need. Run:
git remote -v
Typical output:
origin git@github.com:alice/project.git (fetch)
origin git@github.com:alice/project.git (push)
That tells you the remotes configured for this local Git repository and the exact clone URL(s). The origin shortname is the convention Git assigns to the server you cloned from; the output shows whether the URL uses SSH (git@github.com:owner/repo.git) or HTTPS (https://github.com/owner/repo.git). The official Git book documents git remote -v as the way to list remotes and URLs: Git Basics - Working with Remotes. Atlassian’s tutorial also explains how to read git remote -v output and what origin represents: https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-remote.
If you prefer a single-line URL without the fetch/push labels:
git config --get remote.origin.url
# or
git remote get-url origin
Both return just the URL, e.g. git@github.com:alice/project.git.
Use git config or inspect .git/config for the clone URL
The remote URLs are stored in your repo’s config. You can read them directly:
cat .git/config
You’ll see a block like:
[remote "origin"]
url = https://github.com/alice/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
Programmatic access is handy in scripts:
git config --get remote.origin.url
Stack Overflow threads and many tutorials recommend these commands as reliable ways to get the stored clone URL (for example, see https://stackoverflow.com/questions/2397228/how-to-find-the-original-url-of-a-git-repository-clone and https://stackoverflow.com/questions/1036324/how-to-determine-the-original-clone-url-of-a-local-git-repository). FreeCodeCamp and GeeksforGeeks also summarize the same commands and the origin convention: https://www.freecodecamp.org/news/git-remote-add-origin-how-to-add-a-remote-repository-to-git/ and https://www.geeksforgeeks.org/how-to-find-the-remote-url-of-a-git-repository/.
Note: git remote get-url origin is a modern convenience; git config --get remote.origin.url is portable and script-friendly.
Identify the GitHub fork: origin vs upstream
Cloned a project with multiple forks? Which one did you pull from? Here’s how to tell.
-
Look at the owner in the remote URL. If
originisgit@github.com:yourusername/project.gitorhttps://github.com/yourusername/project.git, you likely cloned your fork. If it’shttps://github.com/original-owner/project.git, then you cloned the parent repo. -
Check whether an
upstreamremote exists:
git remote -v
# look for "upstream"
If there’s no upstream, the repo you cloned from is whatever origin points to. If you want to add the original repository as an upstream remote (common workflow for forks), run:
git remote add upstream https://github.com/original-owner/project.git git fetch upstream
GitHub docs explain this fork workflow and adding an upstream remote: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-for-a-fork.
- Want to be sure programmatically? Open the remote’s GitHub web URL (convert SSH to HTTPS if needed:
git@github.com:owner/repo.git→https://github.com/owner/repo). The GitHub repository page shows “forked from” when relevant. Or query the GitHub API for the repo JSON; it includes aforkboolean and aparentobject when a repo is a fork:
curl -s https://api.github.com/repos/owner/repo | jq '.fork, .parent.full_name'
(You’ll need jq or parse the JSON by hand. Private repos require auth.)
DigitalOcean and other tutorials cover using git remote and fetch workflows for syncing forks: https://www.digitalocean.com/community/tutorials/how-to-use-git-effectively.
When remotes were changed or removed — what you can (and can’t) recover
Short answer: Git stores remotes in the repo config, and that’s the source of truth. If someone later changed or removed origin, Git doesn’t keep a history of prior remote URLs inside the repo by default. That means you may not be able to recover the original clone URL from Git alone.
Options if the remote has been altered or deleted:
- Check your shell history (
history | grep git) — maybe the originalgit clonecommand is still in it. - Inspect backups or dotfiles on the machine where you originally cloned.
- Look for references to the remote in CI configs, README, package files, or documentation inside the repo — sometimes the real remote is mentioned.
- If the repo was hosted on GitHub, search the GitHub network graph or fork list in the web UI to find likely parents.
- If you have no local trace, ask teammates or check project records; sometimes the hosting service keeps fork/parent metadata even if you lost the local pointer.
So: try local clues first, then hosting-site info. But don’t expect Git to have a time machine for removed remote URLs.
Quick checklist and commands to run now
Run these in your repo root and read the outputs:
- Show remotes and owners:
git remote -v
- Get only the origin URL:
git config --get remote.origin.url
# or
git remote get-url origin
- Inspect remote details:
git remote show origin
- Read raw config:
cat .git/config
- If you think your origin is a fork and you want the parent:
- Convert the origin URL to a browser URL and open it, or
- Query GitHub:
curl -s https://api.github.com/repos/OWNER/REPO | jq '.fork, .parent.full_name'
- To add the original repository as
upstream(so you can pull upstream changes):
git remote add upstream https://github.com/original-owner/repo.git git fetch upstream
If a remote returns 404 or permission denied, the repo might be private or removed. In that case you’ll need proper access or owner help.
Sources
- How to find the original URL of a Git repository clone - Stack Overflow
- How to determine the original clone URL of a local Git repository - Stack Overflow
- Git Remote Add Origin: How to Add a Remote Repository to Git — freeCodeCamp
- Git remote - Atlassian Git Tutorial
- Git Basics - Working with Remotes — Git Book
- How to find the remote URL of a Git repository? — GeeksforGeeks
- How To Use Git Effectively — DigitalOcean
- How to determine if a Git repository is a fork of another - Stack Overflow
- Configuring a remote for a fork - GitHub Docs
Conclusion
In most cases the Git original clone URL is right in your local Git configuration — git remote -v reveals it, and git config --get remote.origin.url or git remote get-url origin returns a clean URL. For GitHub forks check whether an upstream remote exists or inspect the repo page/API to identify the parent; if origin was changed or removed after clone, there may be no built-in record to recover.