Tutorial: How to Manage Remote Repositories with Git
In this tutorial, you will learn how to check the remote URL of your Git repository, as well as how to add and remove a remote repository.
Check the Remote URL
To see which remote repository your Git project is pointing to, you can use the following command:
git remote -v
This command will show you something like the following:
origin https://github.com/user/repository.git (fetch)origin https://github.com/user/repository.git (push)
Remove a Remote Repository
If you want to remove a remote repository (e.g., origin
), you can use the following command:
git remote remove origin
This will remove the reference to the remote repository named origin
.
Add a New Remote Repository
To add a new remote repository, use the following command:
git remote add origin <URL-of-the-new-repository>
Replace <URL-of-the-new-repository>
with the URL of the new repository you want to point to. For example:
git remote add origin https://github.com/user/new-repository.git
Complete Example
Here is a complete example of how to check, remove, and add a remote repository:
-
Check the Remote URL:
Terminal window git remote -vExpected output:
origin https://github.com/user/repository.git (fetch)origin https://github.com/user/repository.git (push) -
Remove the Current Remote Repository:
Terminal window git remote remove origin -
Add a New Remote Repository:
Terminal window git remote add origin https://github.com/user/new-repository.git -
Check the New Remote URL:
Terminal window git remote -vExpected output:
origin https://github.com/user/new-repository.git (fetch)origin https://github.com/user/new-repository.git (push)
And that’s it! Now you know how to manage your remote repository URLs in Git.