Change a Git Remote Repository URL

Changing a remote repository URL

Use git remote set-url to change an existing remote repository URL.

Check the connected Git repository

Before changing it, check which remote repository the current local Git repository is connected to with git remote -v.

$ git remote -v
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Change the connected Git repository

After checking the current remote, enter the command in the following format to change the remote repository URL.

git remote set-url origin <new remote repository URL>

Example:

$ git remote set-url origin https://github.com/user/repo2.git

The command takes two arguments:

  • origin: the existing remote repository name.
  • https://github.com/user/repo2.git: the new remote repository URL.