Git

How to Change Git Remote Origin(URL)

Git is an independent versioning system used to push and pull a source code of project files to a remote origin. Its users are allowed to make multiple branches on a local repository for different modules. After that, it can be required to push them to the GitHub hosting service. Moreover, sometimes developers also want to migrate the Git repository for some reason. For that, it is necessary to set the new origin(url).

This article will provide

So, let’s begin!

How to Change Git Remote Origin Using HTTPS URL?

To change a Git remote origin using an HTTPS URL, first, open the Git terminal and check the existing remote URL. Next, switch to the remote repository and copy the HTTPS URL. Then, execute the “$ git remote set-url origin <https-url>” command to set the new origin.

Now, let’s move toward the implementation of the above-discussed scenario!

Step 1: Check Remote Origin(URL)
Run the below-provided command to view the existing remote origin:

$ git remote -v

Step 2: Copy HTTPS URL
Next, open up the desired remote repository, click on the below-highlighted button and copy the HTTPS URL:

Step 3: Set Remote Origin(URL)
Finally, set the remote origin by utilizing the “git remote set-url origin” command with the copied URL:

$ git remote set-url origin https://github.com/GitUser0422/demo3.git

Step 4: Verification
Lastly, verify the set remote origin through the following command:

$ git remote -v

It can be seen that the new remote origin(url) is changed successfully:

Let’s check out the next section to change the remote origin using the SSH URL.

How to Change Git Remote Origin Using SSH URL?

Git users can change the remote origin using the SSH URL. To do so, copy the SSH URL of the Git remote repository. Then, run the “$ git remote set-url origin <https-url>” command to set the new origin using the SSH URL.

Step 1: Copy SSH URL
To copy the SSH URL, go to the remote repository, press the “Code” button, and click on the provided SSH URL:

Step 2: Change Remote Origin
Now, execute the “git remote set-url origin” command with copied SSH URL to change the existing remote origin:

$ git remote set-url origin git@github.com:GitUser0422/demo3.git

Step 3: Verify Changed Origin(URL)
To verify the changed remote origin, run the following command:

$ git remote -v

According to the below output, the remote origin is changed successfully:

That’s it! We have offered the easiest methods to change the remote origin using HTTPS and SSH URLs.

Conclusion

Users can change the remote using HTTPS or SSH URLs. For this purpose, first, check the existing remote origin. Then, switch to the GitHub hosting service and copy the required remote repository URL. Lastly, execute the “$ git remote set-url origin <remote-url>” command to update the remote origin. This manual demonstrated changing the remote origin using HTTPS and SSH URLs.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.