How to Update Git Origin URL?


To update the origin URL of your Git repository (i.e., the remote repository URL), you can use the git remote set-url command.

Here’s how to do it -

Steps to Update the Origin URL:

  1. Check the Current Remote URL: To see the current URL associated with origin, you can run

    git remote -v
    
    This will show the current URLs for both fetching and pushing.
  2. Update the Remote URL: If you want to change the origin URL, you can use the following command 

    git remote set-url origin <new-url>
    

    Replace <new-url> with the new URL you want to use.


Example:

Let's say the original remote URL is https://github.com/olduser/oldrepo.git, and you want to change it to git@github.com:newuser/newrepo.git.


Check the current remote URL 

git remote -v

Update the origin to the new SSH URL:

git remote set-url origin git@github.com:newuser/newrepo.git

Verify the update

git remote -v

After this, your Git repository will be connected to the new remote URL!