Introduction
- Git is a decentralized version control system, so any changes you make on your local computer should be pushed to a centrally hosted remote repository.
- Git remote is a pointer that points to copies of a repository hosted on a reliable remote server, such as GitHub or GitLab. It enables collaboration, pushing and pulling changes, and keeping local repos up to date.
In some cases, you might choose to migrate your Git repository or to merge existing ones.
As a consequence, you may need to change the Git origin
remote to a new URL in local machines.
This guide details the steps to change the URL of a Git remote locally.
Changing a Git Remote URL
In order to modify the URL of a Git remote in a local machine, you must utilize the command git remote set-url
, indicating the name of the remote (For example: origin
) and the new URL to assign.
Step 1: Navigate to the directory containing the repository:
cd /path/to/repository
Step 2: Run git remote -v
to list the existing remotes, and to view their names and URLs:
git remote -v
The output will look something like this:
origin https://example_domain/user/current_repo_name.git (fetch)
origin https://example_domain/user/current_repo_name.git (push)
Step 3: Run the git remote set-url
command, followed by the remote's name and URL:
You can find the HTTPS and SSH Repository URL from the Project information page in GitLab.
To change the URL of the origin to https://company_name.vegaops.com/user/repository.git
, you would run:
git remote set-url origin https://company_name.vegaops.com/user/repository.git
To check that the Git Remote URL has been set up correctly, run the git remote
command with the v
(verbose) option:
git remote -v
The expected outcome should look something like this:
origin https://company_name.vegaops.com/user/repository.git (fetch)
origin https://company_name.vegaops.com/user/repository.git (push)
✅ You have completed the process of changing the URL of the remote.
Conclusion
The git remote set-url
command updates the repository's .git/config
file with a new URL pointing to the remote repository.