This post discusses the procedure to change the URL for remote Git repositories to HTTPS and SSH URLs.
Change the Git Remote Repository URI (URL) to HTTPS?
To change the URL for the remote Git repository to the HTTPS URL, firstly, open the GitHub hosting service, and navigate to the remote repository. Then, copy the HTTPS and move to the desired directory where the local repository is located. Lastly, execute the “$ git remote set-url origin <https-url>” command.
Now, let’s move toward the implementation of the above-discussed instructions!
Step 1: Copy HTTPS URL
First, visit GitHub and open the desired remote repository. Then, hit the below-highlighted button and copy the HTTPS URL:
Step 2: Navigate to Directory
Navigate to the desired directory where the local repository is located using the “cd” command:
Step 3: Check Remote List
Next, execute the “git remote” command with the “-v” option to list the existing remotes and view their URLs along with the name:
It can be seen that currently, some SSH remote connection exists:
Step 4: Set HTTPS URL
Now, run the “git remote set-url” command with the copied HTTPS URL:
Step 5: Verify Added Remote
Lastly, execute the provided command to ensure the remote(origin) is added:
As you can see, the URL is successfully changed to HTTPS:
Let’s move ahead to the next section to change the URL for the remote Git repository to SSH.
Change the Git Remote Repository URI (URL) to SSH?
To add the SSH URL for the remote Git repository, firstly, open the remote repository. Then, hit the “Code” button and copy the SSH. Move to the desired directory where the local repository is located. Execute the “$ git remote set-url origin <ssh-url>” command to add the SSH URL for a remote Git repository.
Now, follow the below provided instructions to understand the discussed procedure!
Step 1: Copy SSH URL
Open your Git remote repository, hit the “Code” button, and copy the SSH URL:
Step 2: Set SSH URL
Next, run the “git remote set-url” command along with the remote repository name and URL:
Step 3: Verify List Connections
Lastly, run the “git remote” command along with the “-v” option to verify the performed operations:
The below output shows that the URL for the remote Git repository is changed:
We have offered the methods to change the URL for remote Git repositories to HTTPS or SSH URLs.
Conclusion
To change the URL for the remote Git repository to HTTPS or SSH URL, firstly, open the GitHub hosting service and go to the desired remote repository. Then, copy the HTTPS or SSH URL and move to the desired directory where the local repository is located. Used the “$ git remote set-url origin <remote-url>” command. This post illustrated the methods for changing the remote Git repository URL to HTTPS or SSH URLs.