How To Change Git Remote Origin


To change the remote origin in Git, you can follow the steps below:

  1. First, navigate to your Git repository in the command line or terminal.
  2. Check the current remote URL using the command:
git remote -v

This will show the list of all the remote repositories that are currently associated with your repository.

  1. To change the remote origin URL, use the following command:
git remote set-url origin <new-remote-url>

Here, replace <new-remote-url> with the new URL that you want to set as the remote origin.

  1. Verify that the new remote URL has been set correctly using the command:
git remote -v

Suppose the current remote origin URL is https://github.com/oldusername/oldrepository.git, and you want to change it to https://github.com/newusername/newrepository.git.

  1. Open the command line or terminal and navigate to your Git repository.
  2. Check the current remote URL using the command:
git remote -v

This will show the list of all the remote repositories that are currently associated with your repository. The output might look something like this:

origin  https://github.com/oldusername/oldrepository.git (fetch)
origin  https://github.com/oldusername/oldrepository.git (push)
  1. To change the remote origin URL, use the following command:
git remote set-url origin https://github.com/newusername/newrepository.git

Here, we are using the git remote set-url command to set the new remote URL. Replace https://github.com/newusername/newrepository.git with the new URL that you want to set as the remote origin.

  1. Verify that the new remote URL has been set correctly using the command:
git remote -v

This will show the updated list of all the remote repositories associated with your repository, including the new remote URL that you just set. The output should look something like this:

perlCopy codeorigin  https://github.com/newusername/newrepository.git (fetch)
origin  https://github.com/newusername/newrepository.git (push)

That’s it! You have now successfully changed the Git remote origin