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

ID : 67

viewed : 373

Tags : gitgithubgit-remotegit





Top 5 Answer for github - How can I determine the URL that a local Git repository was originally cloned from?

vote vote

95

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: 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 the script, you would use the first command listed in this answer.

vote vote

81

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

git config --get remote.origin.url 
vote vote

74

You can try:

git remote -v 

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

vote vote

70

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 (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).

vote vote

60

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.

get-url: 

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] 

Top 3 video Explaining github - How can I determine the URL that a local Git repository was originally cloned from?







Related QUESTION?