Set(Origin) Remote Repository URL in Git

The best thing about git is it allows us to manage projects in a very efficient manner. The remote repository can be connected to the local git repository using two methods: over HTTPs and via SSH connection.

Set Origin URL (Remote Repository URL)

Firstly, you can check if the present repository is associated with any remote repository by using the following command.

git remote -v

If the repository exists and uses HTTPS, it will display the following result:

origin	https://github.com/user/repo-one (fetch)
origin	https://github.com/user/repo-one (push)

If the repository exists and uses SSH, it will display the following result:

origin	git@github.com:user/repo-one.git (fetch)
origin	git@github.com:user/repo-one.git (push) 

And it will display blank if no remote repository is connected with the repo.

You can remove the associated URL with the use of the following command:

git remote remove origin
Note

The name origin might be different, be sure to check that using git remote -v.

Now that you are sure about the existence of the remote repository, you can set the origin URL as:

git remote set-url origin https://github.com/user/another-repo

Alternatively, if the remote repository URL does not exist, we can use the following command too:

git remote add origin https://github.com/user/another-repo

However, if you want to add another remote repository URL, the first method with git remote set-url origin https://github.com/user/some-other-repo will replace the previous URL of origin. We can use git remote add and add another URL in the same repository to overcome that issue.

Example:

git remote add secondorigin https://github.com/user/another-repo
Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Git Repository

  • Uninitialize Repository in Git
  • Update a Forked Repository
  • Remove Files From a Repository in Git
  • Related Article - Git Origin

  • Uninitialize Repository in Git
  • Update a Forked Repository
  • Remove Files From a Repository in Git