How to check the URL of a local Git repository

To check the URL of a local Git repository, use the command git remote -v. This will show the URLs of remote repositories that are configured for the local repository and the name of the remote (usually “origin”). If you want more detailed information about a particular remote, use git remote show, replacing it with the name of the remote you want to inspect.

git remote -v

git remote -v

For example, if you run the command in a local repository that is linked to a remote repository called “origin,” the output will look like this:

origin  git@github.com:YourUsername/YourRepository.git (fetch)
origin  git@github.com:YourUsername/YourRepository.git (push)

The git config command shows only the URLs for remote repositories that you’ve added to your local repository, not those added by other developers.

The above output lists the URLs of remote repositories and the name of the remote associated with them. In this command, you can see the fetch and push URLs for each remote repository. The fetch URL is where Git will pull updates from, while the push URL is where Git will push commits to. These URLs can be different if you have different permissions for fetching and pushing.

The -v flag stands for “verbose”, and it makes the command display more information about the remote repository. This information includes the remote’s name, its URLs for fetching and pushing, and whether the last fetch was successful.

git remote show origin

The other way is to use git remote show origin command. The git remote show origin command displays detailed information about the remote repository named “origin”. This information includes configuration details for the remote repository, as well as a list of branches that track this remote repository. This command will provide more information about the remote repository.

Example:

 git remote show origin

Detailed output:

* remote origin
  Fetch URL: git@github.com:YourUsername/YourRepository.git
  Push  URL: git@github.com:YourUsername/YourRepository.git
  HEAD branch: main
  Remote branches:
    develop tracked
    main    tracked
    patch-33 tracked
  Local branches configured for 'git pull':
    develop merges with remote develop
    main    merges with remote main
  Local refs configured for 'git push':
    develop pushes to develop (up to date)
    main    pushes to main    (up to date)

The command’s output shows you the remote’s URL(s), its branches, any local branches that track the remote’s branches, and when the last fetch from the remote happened.

git config remote.origin.url

Another useful command for checking the remote is to use git config remote.origin.url. The git config remote.origin.url command is used in Git to display the URL of a remote repository named “origin”.

You can also use the following command to get the URL:

git config remote.origin.url

This command allows you to check the location where Git will pull updates from and push commits to. The remote.origin part of the command specifies that we’re looking for the configuration of the remote named “origin”, and the url part specifies that we’re looking for the URL of that remote.

Output:

git@github.com:YourUsername/YourRepository.git

This means that the remote repository named “origin” is located at the URL git@github.com:YourUsername/YourRepository.git