doc/tutorials/update_git_remote_url/_index.md
{{< details >}}
{{< /details >}}
Update your Git remote URLs if:
[!note] If you don't have an existing local working copy from the old remote, then you don't need this tutorial. You can instead clone the project from the new GitLab URL.
This tutorial explains how to update the remote URL for your local repository without:
This tutorial uses the git-remote command to
manage remote and tracked repositories.
To update Git remote URLs:
You must have:
To update the Git remote URL, determine the existing and new URLs for your repository:
Open a terminal or command prompt.
Go to your local repository working copy. To change directory, use cd:
cd <repository-name>
Each repository has a default remote named origin. To view the current remote fetch and push URLs
for your remote repository, run:
git remote -v
Copy and keep note of the returned URLs. They are usually identical.
Get the new URL:
git,
copy either the HTTPS or SSH URL. If you're not sure, use the same method as the origin URL from the previous step.To update the Git remote URL:
Open a terminal or command prompt.
Go to your local repository working copy. To change directory, use cd:
cd <repository-name>
Update the remote URL, replacing <new_url> with the new repository URL you copied:
git remote set-url origin <new_url>
Verify that the remote URL update is successful. The following command displays the new URL for both fetch and push operations, lists the local branches, and confirms that they are tracked to GitLab:
git remote show origin
<new_url>, and try again.To update the remote URLs for multiple repositories:
Use the git remote set-url command. Replace origin with the name of the
remote you want to update. For example:
git remote set-url <remote_name> <new_url>
Verify each remote URL update:
git remote show <remote_name>
After updating the remote URL, you can continue to use Git commands as usual.
Your next git fetch, git pull, or git push uses the new URL from GitLab.
Congratulations, you have successfully updated the remote URL for your repository.
Your project might have more than one remote location. For example, you have a forked repository from a project hosted on GitHub, but you want to work on your fork in GitLab before you make a pull request to GitHub.
To keep the original remote URL in addition to updating it, and maintain both new and old remote URLs, you can add a new remote instead of modifying the existing one.
With this approach, you can gradually transition to the new URL while still maintaining access to the original repository.
To add a new remote URL:
Open a terminal or command prompt.
Go to your local repository working copy.
Add a new remote URL. Replace <new_remote_name> with a name for the new remote,
for example, new-origin, and <new_url> with the new repository URL:
git remote add <new_remote_name> <new_url>
Verify that the new remote was added:
git remote -v
Now you can use both the original and new remotes. For example:
git push origin maingit push <new_remote_name> main