How can I determine the URL that a local Git repository was originally cloned from?

Created 03.11.2010 16:47
Viewed 3.25M times
4516 votes

I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, and I neglected to note which one I took originally. How can I determine which of those forks I pulled?

With git 2.7 (Q4 2015), git remote get-url origin will be possible. See my answer below by VonC, 07.10.2015 12:08… by Developine, 19.01.2017 10:55
git remote get-url origin does not work for me--possibly deprecated? git remote show origin worked though. by Klik, 25.10.2017 16:47
git remote -v give you a lot of information, including this. by Thorbjørn Ravn Andersen, 10.12.2017 12:21
git remote get-url origin --push works fine, apparently not depreciated and provides nice brief info (git remote show origin can be very verbose) q.v. git help remote. by NeilG, 22.08.2019 02:30
Answers 26

If you want only the remote URL, or if your are not connected to a network that can reach the remote repo:

git config --get remote.origin.url

If you require full output and you are on a network that can reach the remote repo where the origin resides :

git remote show origin

When using git clone (from GitHub, or any source repository for that matter) the default name for the source of the clone is "origin". Using git remote show will display the information about this remote name. The first few lines should show:

C:\Users\jaredpar\VsVim> git remote show origin
* remote origin
  Fetch URL:
  Push  URL:
  HEAD branch: master
  Remote branches:

If you want to use the value in the script, you would use the first command listed in this answer.

03.11.2010 16:50
Use git config as described below instead if using jgit with amazon-s3. by barryku, 29.03.2012 17:20
Although not relevant to the purpose of the original question, please note that if attempting to get the "Push URL" and multiple URLs are entered for the remote specified, you'll either need to use git remote show origin (optionally with the -n flag provided by @Casey), or with git remote -v as suggested by @Montaro and @rodel. by Amazingant, 24.07.2014 14:39
What file is this written to? I thought the .gitconfig file would have it, but I didn't see it in mine. by ayjay, 04.12.2014 21:15
@ayjay ´~/.gitconfig is global to all git repositories, this here comes from the local config which usually is in .git/config (however for git-submodules the answer is a bit more difficult). Note that strace git config --get remote.origin.url is your friend. by Tino, 07.12.2014 09:10
But the original URL doesn't have to be the URL of the currently used remote. To show the actual used URL, you would need this solution then: by rubo77, 16.11.2016 11:30
This answer will be the best until cent os drops git 1.x by kujiy, 29.03.2018 02:21
Note: the approach git remote show origin doesn't work if the stored credentials do no longer have required access rights to the original repository. In such case, try git remote -v by Cédric Françoys, 04.10.2018 11:59
I removed the phrase "referential integrity" as it is misleading in the context of git. Searching the git docs for the phrase reveals no hits The first command works when you are offline and the second works only if you are online. by Rob Kielty, 13.08.2019 08:19
I turned off my wifi and I am no longer connected to the network, and still get remote get-url origin still showed correctly the remote repository URL. by eigenfield, 05.09.2020 07:18
git config --get remote.origin.url this works for me by piupaul, 26.12.2020 07:25
Show remaining 5 comments

Should you want this for scripting purposes, you can get only the URL with

git config --get remote.origin.url
03.11.2010 19:35
This is the correct answer. It is way faster and it even works, if the remote url is not available anymore (git remote show origin just shows "conq: repository does not exist."). by apfelbox, 22.05.2013 06:58
This is not quite the right answer because of the config option url.<base>.insteadOf. See my answer - git has a command for this purpose. by Carl Suster, 02.06.2013 05:17
@arcresu Cool, +1 to you! In my defense, that command wasn't added until March 2011, and it wasn't documented until September 2012. by Cascabel, 02.06.2013 06:03
@Catskul Only --git-dir is relevant (the config is in the git dir, independent of work tree location), and it does work for me. Are you sure you specified the path to the actual .git dir, not its parent directory? by Cascabel, 21.03.2014 21:53

You can try:

git remote -v

It will print all your remotes' fetch/push URLs.

29.01.2012 12:01
It's also usually used as short for -verbose by Montaro, 23.07.2020 14:10
@Montaro exactly, without it, only the name of the remote is printed (e.g. origin). by CPHPython, 18.11.2020 10:03

To get the answer:

git ls-remote --get-url [REMOTE]

This is better than reading the configuration; refer to the man page for git-ls-remote:


Expand the URL of the given remote repository taking into account any "url.<base>.insteadOf" config setting (See git-config(1)) and exit without talking to the remote.

As pointed out by @Jefromi, this option was added in v1.7.5 and not documented until v1.7.12.2 (2012-09).

02.06.2013 05:15
good one : this also would provide the same for previous versions > git remote -v| grep fetch|awk '{print $2}' by ravi.zombie, 17.07.2015 20:26
I think most of the other answers are more of a show-and-tell about git commands and exposition about git history. This is the only answer that doesn't assume your upstream is called origin. by Mike D, 18.12.2018 14:41
This is the most direct replacement for the old remote get-url option. It's a drop-in replacement. by Klaatu von Schlacker, 15.03.2019 22:07

With Git 2.7 (release January 5th, 2015), you have a more coherent solution using git remote:

git remote get-url origin

(nice pendant of git remote set-url origin <newurl>)

See commit 96f78d3 (16 Sep 2015) by Ben Boeckel (mathstuf).
(Merged by Junio C Hamano -- gitster -- in commit e437cbd, 05 Oct 2015):

remote: add get-url subcommand

Expanding insteadOf is a part of ls-remote --url and there is no way to expand pushInsteadOf as well.
Add a get-url subcommand to be able to query both as well as a way to get all configured URLs.


Retrieves the URLs for a remote.
Configurations for insteadOf and pushInsteadOf are expanded here.
By default, only the first URL is listed.

  • With '--push', push URLs are queried rather than fetch URLs.
  • With '--all', all URLs for the remote will be listed.

Before git 2.7, you had:

 git config --get remote.[REMOTE].url
 git ls-remote --get-url [REMOTE]
 git remote show [REMOTE]
07.10.2015 12:07
After 5 years a lot has changed and this should be the accepted answer now. But maybe add the pre-2.7 syntax as well. by msp, 14.12.2015 08:17

To summarize, there are at least four ways:

(The following was tried for the official Linux repository)

Least information:

$ git config --get remote.origin.url


$ git ls-remote --get-url

More information:

$ git remote -v
origin (fetch)
origin (push)

Even more information:

$ git remote show origin
* remote origin
  Fetch URL:
  Push  URL:
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
15.05.2014 15:28
Note git config --get remote.origin.url retrieves the original URL which was set with git remote add ... or git remote set-url ... while git ls-remote --get-url origin retrieves the URL which is actually used to access the remote - which might be different in presence of git config --global url.XXX.insteadOf YYY. So both outputs may differ! Also note that git ls-remote --get-url (without origin) does not neccessarily retrieve origin, instead it shows the tracked upstream, so it will fail for example in detached HEAD state. by Tino, 07.12.2014 09:27

I think you can find it under .git/config and remote["origin"] if you didn't manipulate that.

03.11.2010 16:50

For me, this is the easier way (less typing):

$ git remote -v
origin (fetch)
origin (push)

actually, I've that into an alias called s that does:

git remote -v
git status

You can add to your profile with: alias s='git remote -v && git status'

11.02.2019 18:39

Short answer:

$ git remote show -n origin

or, an alternative for pure quick scripts:

$ git config --get remote.origin.url

Some info:

  1. $ git remote -v will print all remotes (not what you want). You want origin right?
  2. $ git remote show origin much better, shows only origin but takes too long (tested on git version 1.8.1.msysgit.1).

I ended up with: $ git remote show -n origin, which seems to be fastest. With -n it will not fetch remote heads (AKA branches). You don't need that type of info, right?

You can apply | grep -i fetch to all three versions to show only the fetch URL.

If you require pure speed, then use:

$ git config --get remote.origin.url

Thanks to @Jefromi for pointing that out.

27.02.2013 18:11

I can never remember all the parameters to Git commands, so I just put an alias in the ~/.gitconfig file that makes more sense to me, so I can remember it, and it results in less typing:

url = ls-remote --get-url

After reloading the terminal, you can then just type:

> git url

Here are a few more of my frequently used ones:

cd = checkout
ls = branch
lsr = branch --remote
lst = describe --tags

I also highly recommend git-extras which has a git info command which provides much more detailed information on the remote and local branches.

14.01.2018 19:57
I like this a lot! by Alfie, 26.06.2019 07:53
Nice aliases, I love how they meld very naturally with bash commands. I can see this being causing the least amount of mental friction when switching between bash and git. Bravo! by seeker, 05.08.2020 01:37

The Git URL will be inside the Git configuration file. The value corresponds to the key url.

For Mac and Linux use the commands below:

 cd project_dir
 cat .git/config | grep url | awk '{print $3}'

For Windows open the below file in any text editor and find the value for key url.


Note: This will work even if you are offline or the remote git server has been taken down.

21.09.2017 10:50
This is what worked for me once the remote server that hosted the original checkout was taken down. All the other attempts failed: git remote get-url origin >> fatal: No such remote 'origin', git config --get remote.origin.url >> by jxramos, 11.09.2018 18:21

I prefer this one as it is easier to remember:

git config -l

It will list all useful information such as: Name
12.02.2020 09:55

I basically use:

git remote get-url origin

It works for Git Bash command console or CMD command console in Windows. That said, it works with version 2.x of Git.

10.10.2017 19:16
git config --list

This command will give all information related to your repository.

28.05.2019 07:20

The upstream's remote may not be called "origin", so here's a variation:

remote=$(git config --get branch.master.remote)
url=$(git config --get remote.$remote.url)
basename=$(basename "$url" .git)
echo $basename


basename $(git config --get remote.$(git config --get branch.master.remote).url) .git

For more useful variables there's:

$ git config -l
19.04.2013 20:49

To get the IP address/hostname of origin

For ssh:// repositories:

git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d "/"

For git:// repositories:

git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d ":"
24.06.2014 20:54
For ssh this only works in absence of ~/.ssh/config which rewrites the hostname or alias. by Tino, 07.12.2014 09:33

With git remote show origin you have to be in the projects directory. But if you want to determine the URLs from anywhere else you could use:

cat <path2project>/.git/config | grep url

If you'll need this command often, you could define an alias in your .bashrc or .bash_profile with MacOS.

alias giturl='cat ./.git/config | grep url'

So you just need to call giturl in the Git root folder in order to simply obtain its URL.

If you extend this alias like this

alias giturl='cat .git/config | grep -i url | cut -d'=' -f 2'

you get only the plain URL without the preceding




you get more possibilities in its usage:


On Mac you could call open $(giturl) to open the URL in the standard browser.

Or chrome $(giturl) to open it with the Chrome browser on Linux.

21.11.2015 08:41

A simple way is to open the .git/config file:

cat .git/config

To edit:

vim .git/config or

nano .git/config

01.02.2017 11:05
This presumes you are on Linux(?). by Peter Mortensen, 25.07.2018 20:15

To supplement the other answers: If the remote has for some reason been changed and so doesn't reflect the original origin, the very first entry in the reflog (i.e. the last entry displayed by the command git reflog) should indicate where the repo was originally cloned from.


$ git reflog | tail -n 1
f34be46 HEAD@{0}: clone: from

(Bear in mind that the reflog may be purged, so this isn't guaranteed to work.)

16.11.2015 12:58
This is probably the only real way to get the "original" remote if it has been changed. by Justin Ohms, 20.07.2016 23:57

Print arbitrarily named remote fetch URLs:

git remote -v | grep fetch | awk '{print $2}'
20.01.2013 23:51

You cloned your repo with SSH clone.

git config --get remote.origin.url

But you want to get http url to open it in the browser or share it:

git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'

GitHub or GitLab doesn’t matter.

15.09.2020 18:27
Useful! Doesn't work on https urls though. This one is universal, works for both git@... and https://...: git config --get remote.origin.url | sed -E 's/:([^\/])/\/\1/g' | sed -e 's/ssh\/\/\///g' | sed -e 's/git@/https:\/\//g' by Max Ivanov, 24.01.2021 16:31
If I want an add /pulls for this regex how can I do this @aidargatin by Hasan Tezcan, 27.02.2021 03:35

If you do not know the name of the upstream remote for a branch, you can look that up first by inspecting the upstream branch name that the current branch was built upon. Use git rev-parse like this:

git rev-parse --symbolic-full-name --abbrev-ref @{upstream}

This shows that upstream branch that was the source for the current branch. This can be parsed to get the remote name like this:

git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1

Now take that and pipe it to git ls-remote and you'll get the URL of the upstream remote that is the source of the current branch:

git ls-remote --get-url \
  $(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1)

Now it should be noted, that this is not necessarily the same as the source remote repository that was cloned from. In many cases however it will be enough.

09.08.2017 00:38

git-remote-url() {
 local rmt=$1; shift || { printf "Usage: git-remote-url [REMOTE]\n" >&2; return 1; }
 local url

 if ! git config --get remote.${rmt}.url &>/dev/null; then
  printf "%s\n" "Error: not a valid remote name" && return 1
  # Verify remote using 'git remote -v' command

 url=`git config --get remote.${rmt}.url`

 # Parse remote if local clone used SSH checkout
 [[ "$url" == git@* ]] \
 && { url="${url##*:}" >&2; }; \
 { url="${url%%.git}" >&2; };

 printf "%s\n" "$url"


# Either launch a new terminal and copy `git-remote-url` into the current shell process, 
# or create a shell script and add it to the PATH to enable command invocation with bash.

# Create a local clone of your repo with SSH, or HTTPS
git clone
cd your-repository

git-remote-url origin

03.01.2018 03:35

easy just use this command where you .git folder placed

git config --get remote.origin.url

if you are connected to network

git remote show origin

it will show you the URL that a local Git repository was originally cloned from.

hope this help

14.01.2020 10:47

To get only the remote URL:

git config --get remote.origin.url

In order to get more details about a particular remote, use the

git remote show [remote-name] command

To See Remote Url

git remote show origin

To See where you .git folder placed

git config --get remote.origin.url
20.03.2021 18:51
alias git-repo="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'"
alias git-pr="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g' | sed 's/....$//' | sed -ne 's/$/\/pulls &/p'"

add this expresion to .zshrc or .bashrcs on main directory

after you can use like

27.02.2021 03:36