Change your remote repository URL in three steps
When you need to move a project to a different repository — whether you're switching hosting providers, reorganizing your code, or fixing a misconfigured URL — you change the remote that Git pushes to. A remote is simply the web address Git uses to send your code. You can see your current remote, update it, and verify the change all from the command line.
The most common scenario is updating the origin remote, which is the default location Git pushes to. You'll use the git remote set-url command to point it at a new address. This takes about one minute and doesn't affect your local code or history.
Key Takeaways
- Check your current remote address by running git remote -v in your project folder to see where Git is currently configured to push.
- Update the remote with git remote set-url origin [new-url], replacing the bracketed text with your new repository address from your hosting provider.
- Verify the change worked by running git remote -v again and confirming the new URL appears for both fetch and push.
- Your next git push will send code to the new repository, but you may need to authenticate with the new hosting provider first.
View your current remote before making changes
Open your terminal or command prompt and navigate to your project folder. Run git remote -v (the -v stands for verbose). This shows you every remote Git knows about and the URL for each one.
You'll see output like this:
origin https://github.com/username/old-repo.git (fetch) origin https://github.com/username/old-repo.git (push)
The word origin is the remote's name. Most projects have only one remote called origin, but you can have multiple remotes pointing to different servers. The (fetch) and (push) labels show which URL Git uses when pulling code down and pushing code up. In most cases, both point to the same place.
Update the remote URL with git remote set-url
Once you have your new repository URL from your hosting provider (GitHub, GitLab, Gitea, or wherever you're moving the code), run this command:
git remote set-url origin https://github.com/username/new-repo.git
Replace https://github.com/username/new-repo.git with the actual URL of your new repository. Most hosting providers show this URL on the repository page — look for a button labeled "Clone" or "Code" and copy the HTTPS or SSH link.
If you have multiple remotes and need to change one that isn't origin, replace origin with the remote's name. For example, git remote set-url upstream https://example.com/repo.git.
Verify the change took effect
Run git remote -v again to confirm both the fetch and push URLs now point to your new repository:
origin https://github.com/username/new-repo.git (fetch) origin https://github.com/username/new-repo.git (push)
If you see the old URL still listed, the command didn't run successfully. Check for typos in the URL and try again. If you see the new URL, you're ready to push.
Push your code to the new repository
Your next git push will send your code to the new repository. If you're using HTTPS, Git will prompt you for your username and password (or a personal access token, depending on your hosting provider). If you're using SSH, make sure your SSH key is registered with the new hosting provider.
If you're pushing a branch for the first time to this new remote, use git push -u origin branch-name to set the upstream branch. After that, git push alone will work.
If the new repository is empty, your first push will create all the branches and history. If the new repository already has code, Git will reject the push if the histories don't match — this is a safety feature to prevent accidentally overwriting someone else's work.
Changing the push URL separately from fetch (advanced)
In rare cases, you might want to fetch from one repository but push to another. For example, you might pull updates from an upstream project but push to your own fork. Use git remote set-url --push origin [new-url] to change only the push URL while leaving fetch unchanged.
Run git remote -v to see the result — the fetch and push URLs will now be different. To revert this and make them the same again, use git remote set-url origin [url] without the --push flag, and it will update both.
Frequently Asked Questions
What if I get an error saying "fatal: No such remote"?
This means the remote name you used doesn't exist. Run git remote -v to see the exact names of your remotes. If you see nothing, your repository isn't connected to any remote yet — use git remote add origin [url] instead of set-url.
Will changing the remote delete my local code or history?
No. Changing the remote only tells Git where to send code in the future. Your local files, commits, and branches stay exactly as they are. You can always change the remote back if needed.
Do I need to change the remote on every computer where I work on this project?
Yes. Each clone of the repository has its own remote configuration stored locally. If you work on the same project from a laptop and a desktop, you'll need to run git remote set-url on both machines.
What's the difference between HTTPS and SSH URLs?
HTTPS URLs (starting with https://) prompt for a username and password or token each time you push. SSH URLs (starting with git@) use a key pair stored on your computer, so you don't type credentials. SSH is faster if you push often, but HTTPS is simpler to set up initially.
Can I push to multiple repositories at once?
You can add multiple remotes with different names — for example, git remote add backup https://example.com/backup-repo.git — and then push to each one separately with git push origin and git push backup. You cannot make a single git push go to multiple places without additional configuration.