git remote url git repository

How to Get Remote URL A Local Git Repository Was Cloned From

Git is a popular version control system that allows you to develop complex projects. Typically, developers need to clone a repository before they can work with it. But often you may need to get remote URL from which a local git repository was cloned from. In this article, we will learn how to get remote URL that a local git repository was cloned from.


How to Get Remote URL A Local Git Repository Was Cloned From

It is very easy to get remote URL a local repository was cloned from using the following command.

$ git config --get remote.origin.url

When you clone a remote repository to your system, git will store its remote URL in remote.origin.url. Depending on the repository that you are currently in, git will show the remote URL of that repository.

So if you have two repositories test1 and test2, then when you run the above command after you have navigated to the folder of test1, git will show remote URL of that repository. If you have switched to test2 repository, git will show the remote URL of test2 repository.

On the other hand, if you are already logged into remote repo where origin resides, you can run the following command instead.

$ git remote show origin

You will see output similar to the following.

* remote origin
  Fetch URL: git@github.com:test_user/test_repo.git
  Push  URL: git@github.com:test_user/test_repo.git
  HEAD branch: master
  Remote branches:

In this article, we have learnt how to get remote URL a repository from cloned from. This is common problem faced by beginners in git development.

Also read:

How to Remove File from Git History
How to Get One File from Another Branch in Git
How to Change Git Commit Message
How to Force Git Pull to Overwrite Local Files
How to Delete Git Branch Locally & Remotely

Leave a Reply

Your email address will not be published.