The git remote URL is specified in the .git/config file in a repository's folder. To update a git remote URL, you can do either of the following:
Please be aware of the potential implications of changing the remote URL. For example, if you are collaborating with others on the repository, changing the remote URL could affect their ability to push, fetch, or work with the repository.
Running git remote set-url Command
To change the URL of a remote repository your local repository points to, you can run the following command in terminal:
git remote set-url <remote-name> <repo-url>
For example, if the remote name is "origin" and the remote URL is "[email protected]:designcise/web.git", the command would be:
git remote set-url origin [email protected]:designcise/web.git
After running this command, you can verify the updated remote URL using the following command:
git remote -v
It will show output similar to the following:
# origin [email protected]:designcise/web.git (fetch) # origin [email protected]:designcise/web.git (push)
Manually Editing URL in .git/config File
To manually edit the .git/config file, you can follow these steps:
- Open the
.git/configfile in a text editor; - Search for the section labeled "
[remote "<remote-name>"]", where<remote-name>is the current remote the repository points to; - Edit the corresponding remote URL and save the file.
For example, if the current remote name is "origin" and the current remote URL is "[email protected]:designcise/repo.git", the relevant section in the .git/config file would look like:
[remote "origin"]
url = [email protected]:designcise/repo.git
Here, you can edit the URL to the new repository for the corresponding remote.
After making the changes, you can check if the remote URL has been updated using the following command:
git remote -v
The output will display the updated URLs for fetch and push operations:
# origin [email protected]:designcise/web.git (fetch) # origin [email protected]:designcise/web.git (push)
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.