How to Change a Git Remote URL
If a repository moved, you changed hosting providers, or you want to switch between HTTPS and SSH, update the remote URL with git remote set-url. This changes where Git fetches and pushes; it does not change your local commits.
Check your current Git remotes
List configured remotes and their fetch and push URLs:
git remote -vThe common remote name is origin, but a repository can have any number of remotes with different names. Use the exact name shown in your output.
Change the URL for origin
Replace the existing URL for origin with the new repository URL:
git remote set-url origin <new-url>For an HTTPS remote, use a URL like this:
git remote set-url origin https://github.com/OWNER/REPOSITORY.gitFor SSH, use an SSH URL instead:
git remote set-url origin git@github.com:OWNER/REPOSITORY.gitReplace OWNER and REPOSITORY with the correct values. Use the example that matches the authentication method configured for your account.
Verify the new remote URL
Confirm the change and test that the remote can be reached:
git remote get-url origin
git fetch originIf fetching fails, verify that the URL is correct, the repository exists, and your account or SSH key has access. Changing the URL alone does not grant permission to the repository.
Add a remote if none is configured
If git remote -v shows no remotes, add one instead of trying to update a missing name:
git remote add origin <repository-url>Verify it with git remote -v. Use the repository URL provided by your hosting service and make sure it is the intended project before pushing.
Common remote URL problems
- Remote not found: Check the owner, repository name, and remote name for typos.
- Permission denied: Check that your account has repository access and that your SSH key or HTTPS credential setup is correct.
- Still using the old URL: Run
git remote -vto check whether you updated the right remote. - Unexpected authentication prompt: HTTPS and SSH use different credential methods. Choose the protocol configured for your account.
Avoid putting passwords or access tokens directly in a remote URL. Use your Git host’s recommended credential manager or SSH key setup.
Git remote URL FAQ
Does changing the remote URL affect local commits?
No. It changes the destination Git uses to communicate with a remote. Your local branches and commits remain unchanged.
How do I change a remote name?
Use git remote rename old-name new-name. This changes the local remote name, not the repository URL itself.