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.

Practice Git workflows →

Check your current Git remotes

List configured remotes and their fetch and push URLs:

git remote -v

The 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.git

For SSH, use an SSH URL instead:

git remote set-url origin git@github.com:OWNER/REPOSITORY.git

Replace 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 origin

If 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

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.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →