I pulled a project with several forks on GitHub, but forgot which fork it was. How do I determine which fork I pulled?
-
274With git 2.7 (Q4 2015), `git remote get-url origin` will be possible. See [my answer below](http://stackoverflow.com/a/32991784/6309) – VonC Oct 07 '15 at 12:08
-
35`git remote get-url origin` does not work for me--possibly deprecated? `git remote show origin` worked though. – Klik Oct 25 '17 at 16:47
-
78`git remote -v` give you a lot of information, including this. – Thorbjørn Ravn Andersen Dec 10 '17 at 12:21
-
3`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`. – NeilG Aug 22 '19 at 02:30
27 Answers
To obtain only the remote URL:
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: git@github.com:jaredpar/VsVim.git
Push URL: git@github.com:jaredpar/VsVim.git
HEAD branch: master
Remote branches:
If you want to use the value in a script, you would use the first command listed in this answer.

- 7,243
- 6
- 49
- 61

- 733,204
- 149
- 1,241
- 1,454
-
2Use git config as described below instead if using jgit with amazon-s3. – barryku Mar 29 '12 at 17:20
-
7Although 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. – Amazingant Jul 24 '14 at 14:39
-
What file is this written to? I thought the `.gitconfig` file would have it, but I didn't see it in mine. – ayjay Dec 04 '14 at 21:15
-
2@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. – Tino Dec 07 '14 at 09:10
-
1But 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: http://stackoverflow.com/a/40630957/1069083 – rubo77 Nov 16 '16 at 11:30
-
1Note: 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` – Cédric Françoys Oct 04 '18 at 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 https://git-scm.com/search/results?search=referential%20integrity The first command works when you are offline and the second works only if you are online. – Rob Kielty Aug 13 '19 at 08:19
-
-
Also `git config --get remote.origin.url` will not error out if the directory does not have a initialised repository and instead returns nothing (empty string) – Ben Apr 07 '22 at 20:31
-
This gives only the URL, which is useful for scripting purposes:
git config --get remote.origin.url

- 24,552
- 19
- 101
- 135

- 479,068
- 72
- 370
- 318
-
55This 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."). – apfelbox May 22 '13 at 06:58
-
9This is not quite the right answer because of the config option `url.
.insteadOf`. See my answer - git has a command for this purpose. – Carl Suster Jun 02 '13 at 05:17 -
1@MateenUlhaq I don't really care in this case, but in general please avoid purely stylistic edits - authors are free to write in their preferred style as long as it's clear. – Cascabel Jul 28 '22 at 04:50
-
1TO CHANGE THIS, do: **`git remote set-url origin http://..... `** OR, look here: [https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories] for more directions. And, upvote this comment since it's probably what a bunch of people want to do – Kevin J. Rice May 27 '23 at 22:02
This will print all your remotes' fetch/push URLs:
git remote -v

- 24,552
- 19
- 101
- 135

- 9,240
- 6
- 29
- 30
-
1@Montaro exactly, without it, only the name of the remote is printed (e.g. `origin`). – CPHPython Nov 18 '20 at 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
:
--get-url
Expand the URL of the given remote repository taking into account any
"url.<base>.insteadOf"
config setting (Seegit-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).

- 30,738
- 21
- 105
- 131

- 5,826
- 2
- 22
- 36
-
2good one : this also would provide the same for previous versions > git remote -v| grep fetch|awk '{print $2}' – ravi.zombie Jul 17 '15 at 20:26
-
2I 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`. – Mike D Dec 18 '18 at 14:41
-
This is the most direct replacement for the old ``remote get-url`` option. It's a drop-in replacement. – Klaatu von Schlacker Mar 15 '19 at 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 ofls-remote --url
and there is no way to expandpushInsteadOf
as well.
Add aget-url
subcommand to be able to query both as well as a way to get all configured URLs.
get-url:
Retrieves the URLs for a remote.
Configurations forinsteadOf
andpushInsteadOf
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]

- 1,262,500
- 529
- 4,410
- 5,250
To summarize, there are at least four ways:
Trying it out using the official Linux repository:
Least information:
$ git config --get remote.origin.url
https://github.com/torvalds/linux.git
and
$ git ls-remote --get-url
https://github.com/torvalds/linux.git
More information:
$ git remote -v
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (push)
Even more information:
$ git remote show origin
* remote origin
Fetch URL: https://github.com/torvalds/linux.git
Push URL: https://github.com/torvalds/linux.git
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)

- 146,324
- 131
- 460
- 740
-
10Note `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. – Tino Dec 07 '14 at 09:27
-
For me, this is the easier way (less typing):
git remote -v
Output:
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (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'

- 30,738
- 21
- 105
- 131

- 1,155
- 10
- 15
I think you can find it under .git/config
and remote["origin"]
if you didn't manipulate that.

- 183,342
- 71
- 393
- 434
Short answer:
$ git remote show -n origin
or, an alternative for pure quick scripts:
$ git config --get remote.origin.url
Some info:
$ git remote -v
will print all remotes (not what you want). You want origin right?$ git remote show origin
much better, shows onlyorigin
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?
http://www.kernel.org/pub//software/scm/git/docs/git-remote.html
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.
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:
awk '/url/{print $3}' project_dir/.git/config
For Windows, open the below file in any text editor and find the value for key url
.
project_dir/.git/config
Note: This will work even if you are offline or the remote Git server has been taken down.

- 2,627
- 2
- 25
- 38

- 9,688
- 11
- 84
- 127
-
1This 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 >>` – jxramos Sep 11 '18 at 18:21
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:
[alias]
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:
[alias]
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.

- 6,204
- 5
- 45
- 42
-
1Nice 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! – seeker Aug 05 '20 at 01:37
I prefer this one as it is easier to remember:
git config -l
It will list all useful information such as:
user.name=Your Name
user.email=your.name@notexisting.com
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/mapstruct/mapstruct-examples
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

- 9,845
- 3
- 58
- 67
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.

- 30,738
- 21
- 105
- 131

- 31,138
- 14
- 118
- 137
Easy. Just use this command where your .git folder is placed:
git config --get remote.origin.url
If you are connected to a network,
git remote show origin
it will show you the URL that a local Git repository was originally cloned from.

- 22,894
- 45
- 188
- 319

- 673
- 8
- 19
git config --list
This command will give all information related to your repository.

- 491
- 4
- 11
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
Or:
basename $(git config --get remote.$(git config --get branch.master.remote).url) .git
For more useful variables there's:
$ git config -l

- 30,738
- 21
- 105
- 131

- 457
- 3
- 11
A simple way is to open the .git/config
file:
cat .git/config
To edit:
vim .git/config
or
nano .git/config

- 30,738
- 21
- 105
- 131

- 1,638
- 1
- 19
- 17
You cloned your repository with SSH clone.
git config --get remote.origin.url
git@gitlab.com:company/product/production.git
But you want to get an 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'
https://gitlab.com/company/product/production.git
GitHub or GitLab doesn’t matter.

- 30,738
- 21
- 105
- 131

- 755
- 1
- 7
- 9
-
3Useful! 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'` – Max Ivanov Jan 24 '21 at 16:31
Print arbitrarily named remote fetch URLs:
git remote -v | grep fetch | awk '{print $2}'

- 111
- 1
- 6
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 ":"
-
4For `ssh` this only works in absence of `~/.ssh/config` which rewrites the hostname or alias. – Tino Dec 07 '14 at 09:33
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.
e.g.
$ git reflog | tail -n 1
f34be46 HEAD@{0}: clone: from https://github.com/git/git
$
(Bear in mind that the reflog may be purged, so this isn't guaranteed to work.)

- 5,055
- 1
- 28
- 44
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
"url="
in
you get more possibilities in its usage:
Example
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.

- 30,738
- 21
- 105
- 131

- 2,843
- 1
- 22
- 20
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.

- 1,813
- 17
- 15
#!/bin/bash
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
fi
url=`git config --get remote.${rmt}.url`
# Parse remote if local clone used SSH checkout
[[ "$url" == git@* ]] \
&& { url="https://github.com/${url##*:}" >&2; }; \
{ url="${url%%.git}" >&2; };
printf "%s\n" "$url"
}
Usage:
# 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 git@github.com:your-username/your-repository.git
cd your-repository
git-remote-url origin
Output:
https://github.com/your-username/your-repository

- 1,527
- 1
- 13
- 8
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 the remote URL:
git remote show origin
To see where you .git folder placed:
git config --get remote.origin.url

- 30,738
- 21
- 105
- 131

- 9,657
- 5
- 47
- 47
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 expression to the .zshrc or .bashrc file in the main directory.
After that, you can use like
git-repo
git-pr

- 30,738
- 21
- 105
- 131

- 1,116
- 1
- 11
- 23
My favorite is this (only works for PUBLIC repos).
- Check the pattern
- Check that a web request returns a valid repo.
import re
import requests
def is_github_repo(url):
pattern = re.compile(r'^https://github\.com/[^/]+/[^/]+$')
if not pattern.match(url):
return False
response = requests.head(url)
return response.status_code == 200 and response.headers['Content-Type'].startswith('text/html')
url = 'https://github.com/username/repo-name'
if is_github_repo(url):
print(f'{url} is a GitHub repository.')
else:
print(f'{url} is not a GitHub repository.')

- 668
- 6
- 9