| by Arround The Web | No comments

How to Set(Origin) Remote Repository URL in Git

Git is a decentralized operating system which permits users to manage projects in a well-organized manner. If users make changes locally, they need to push them to the remote repository to keep the project files updated. The local repository is connected with the central repository (remote) by using the two methods over the “SSH” or “HTTP” connection.

This guide will provide the procedure of changing the new and set(Origin) remote repository URL in Git.

How to Set(Origin) Remote Repository URL in Git?

For instance, if we want to set\replace the remote repo URL in Git, first, we will navigate to a specific directory and check the presence of any existing repo URL. After that, set the new remote URL as well as add the new remote repo URL through this process.

Now, let’s move to the procedure!

Step 1: Launch Git Bash

Open up the Git terminal named “Git Bash” from the “Startup” menu:


Step 2: Navigate to Git Repository

Next, move to the Git local repository using the “cd” command and the path of the Git repo:

$ cd "C:\Users\nazma\Git\test"

 

Note: Before setting the repository URL, first you are required to check the presence of any existing Git repository which will be placed with the new one.

Step 3: Check Repository Presence

Execute the below-provided command to check the presence of any existing repo URL:

$ git remote -v

 
As you can see, our current directory is already connected with the remote repository named “first_demo”:


Step 4: Set Remote Repository URL

Now, execute the “git remote” command with the URL of the remote repository which you are required to set:

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

 

Step 5: Verify Set(Origin) URL

To verify the changes that we have made, execute the below-provided command:

$ git remote -v

 
Below output indicates that we have successfully set the new origin remote repository named “demo.git”:

How to Add(Origin) Remote Repository URL in Git?

Sometimes, users want to set a new remote repository URL in Git but it does not exist in Git local repository. For this corresponding purpose, follow the provided steps:

Step 1: Add Remote Repo URL

Execute the “git remote add” command with the URL of the remote repo which you want to add:

$ git remote add origin https://github.com/GitUser0422/first_demo.git

 

Step 2: Verify Added URL

Run the below-provided command to ensure the newly added remote repository URL in Git:

$ git remote -v

 
As you can see, we have successfully added the new origin remote repository named “first_demo”:


We have efficiently compiled the method of changing the new and set(Origin) remote repository URL in Git.

Conclusion

To set(Origin) remote repository URL in Git, first, open up the “Git Bash” terminal, and navigate to the specific Git local repository in which you want to set(Origin) remote repo URL. Next, check the presence of any remote repo URL which we need to set. Then, set the remote repo URL using the “$ git remote set-url origin <url>” command. You can also add the new remote repo URL using the “$ git remote add origin <url>” command. This guide provided the procedure of changing the new and set(Origin) remote repository URL in Git.

Share Button

Source: linuxhint.com

Leave a Reply