Categories
git git-remote github

How to determine the URL that a local Git repository was originally cloned from

4989

I pulled a project with several forks on GitHub, but forgot which fork it was. How do I determine which fork I pulled?

4

  • 247

    With git 2.7 (Q4 2015), git remote get-url origin will be possible. See my answer below

    – VonC

    Oct 7, 2015 at 12:08


  • 32

    git remote get-url origin does not work for me–possibly deprecated? git remote show origin worked though.

    – Klik

    Oct 25, 2017 at 16:47

  • 74

    git remote -v give you a lot of information, including this.

    Dec 10, 2017 at 12:21

  • 2

    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, 2019 at 2:30

6963

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: [email protected]:jaredpar/VsVim.git
  Push  URL: [email protected]: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.

9

  • 2

    Use git config as described below instead if using jgit with amazon-s3.

    – barryku

    Mar 29, 2012 at 17:20

  • 7

    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.

    Jul 24, 2014 at 14:39


  • 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 7, 2014 at 9:10

  • 1

    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: stackoverflow.com/a/40630957/1069083

    – rubo77

    Nov 16, 2016 at 11:30

  • 1

    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

    Oct 4, 2018 at 11:59

703

This gives only the URL, which is useful for scripting purposes:

git config --get remote.origin.url

3

  • 51

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

    – apfelbox

    May 22, 2013 at 6:58

  • 7

    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.

    Jun 2, 2013 at 5:17

  • @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 at 4:50

688

This will print all your remotes’ fetch/push URLs:

git remote -v

1

  • 1

    @Montaro exactly, without it, only the name of the remote is printed (e.g. origin).

    – CPHPython

    Nov 18, 2020 at 10:03