There are various scenario where you want to change the remote’s URL in your git repository.
You can fire git remote set-url
command to change/ update existing remote repository URL.
The git remote set-url
command takes two arguments:
- An existing remote name. For example,
origin
orupstream
are two common choices. - A new URL for the remote. For example:
- If you’re updating to use HTTPS, your URL might look like:
https://gitlab.com/USERNAME/REPOSITORY.git
- If you’re updating to use SSH, your URL might look like:
git@gitlab.com:USERNAME/REPOSITORY.git
- If you’re updating to use HTTPS, your URL might look like:
Now, let’s say you have git repository setup in on GitLab and not you want to move your repository to GitHub or Bitbucket or vice-versa
So, you don’t need to start from scratch or you even don’t need to setup everything to your existing repository in your machine
Change remote URL from GitLab to GitHub
- Open Terminal.
- Change the current working directory to your local project.
- List your existing remotes in order to get the name of the remote you want to change.
git remote -v
origin https://gitlab.com/malayladu/test-project.git (fetch)
origin https://gitlab.com/malayladu/test-project.git (push)
upstream https://gitlab.com/how2why2/test-project.git (fetch)
upstream https://gitlab.com/how2why2/test-project.git (push) - Change your remote’s URL from gitlab to github with the
git remote set-url
command.$ git remote set-url origin https://github.com/malayladu/test-project.gi
t
$ git remote set-url upstream https://github.com/how2why2/test-project.git - Verify that the remote URL has changed.
$ git remote -v
origin https://github.com/malayladu/test-project.git (fetch)
origin https://github.com/malayladu/test-project.git (push)
upstream https://github.com/how2why2/test-project.git (fetch)
upstream https://github.com/how2why2/test-project.git (push)