below is used to add a new remote:

git remote add "origin" [email protected]:User/UserRepo.git

below is used to change the url of an existing remote repository:

git remote set-url "origin" [email protected]:User/UserRepo.git

below will push your code to the master branch of the remote repository defined with "origin" and -u let you point your current local branch to the remote master branch:

git push -u origin main

Documentation

Answer from Shubham Khatri on Stack Overflow
🌐
GitHub
docs.github.com › en › get-started › git-basics › managing-remote-repositories
Managing remote repositories - GitHub Docs
Learn to work with your local repositories on your computer and remote repositories hosted on GitHub. ... To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.
Discussions

set-url origin and add origin
I often get confuse that should I use set-url origin command after adding the origin. No, unless you by mistake entered the wrong url and want to correct it. More on reddit.com
🌐 r/git
6
2
July 8, 2023
when the best scenario to use git remote add?
If you fork a git repository (on github or another service) then it's very useful to have two (or more) remotes both the upstream repository and your own remote repository. More on reddit.com
🌐 r/git
7
0
November 6, 2020
🌐
Git
git-scm.com › book › ms › v2 › Git-Basics-Working-with-Remotes
Git - Working with Remotes
We’ll go over what branches are and how to use them in much more detail in Git Branching. As you just saw, to get data from your remote projects, you can run: ... The command goes out to that remote project and pulls down all the data from that remote project that you don’t have yet. After you do this, you should have references to all the branches from that remote, which you can merge in or inspect at any time. If you clone a repository, the command automatically adds that remote repository under the name “origin”. So, git fetch origin fetches any new work that has been pushed to that server since you cloned (or last fetched from) it.
🌐
Git
git-scm.com › docs › git-remote
Git - git-remote Documentation
Add a remote named <name> for the repository at <URL>. The command git fetch <name> can then be used to create and update remote-tracking branches <name>/<branch>.
🌐
Atlassian
atlassian.com › git › tutorials › syncing
How to Add Remote Git? | Atlassian Git Tutorial
December 16, 2025 - The git remote add command will create a new connection record to a remote repository. After adding a remote, you’ll be able to use <name> as a convenient shortcut for <url> in other Git commands.
🌐
Assembla
articles.assembla.com › all collections › using git › getting started › how to add a new remote to your git repo
How to Add a New Remote to your Git Repo | Assembla Help Center
#set a new remote git remote add my_awesome_new_remote_repo git@git.assembla.com:portfolio/space.space_name.git #Verify new remote git remote -v > my_awesome_new_remote_repo git@git.assembla.com:portfolio/space.space_name.git (fetch) > my_awesome_new_remote_repo git@git.assembla.com:portfolio/space.space_name.git (push)
Find elsewhere
🌐
JanBask Training
janbasktraining.com › community › devops › git-remote-add-origin-vs-remote-set-url-origin
git - remote add origin vs remote set-url origin | JanBask Training Community
August 15, 2025 - This sets the alias origin to point to your GitHub repository. Note: If origin already exists, this command will throw an error. ... This command is used to change the URL of an existing remote. It's helpful when: You’ve renamed your repository. You're switching from HTTPS to SSH. You’ve moved your repo to another hosting service. ... This updates the existing origin without having to delete or re-add it.
🌐
Team Treehouse
teamtreehouse.com › community › why-do-we-use-git-remote-add-origin
Why do we use "git remote add origin..."? (Example) | Treehouse Community
February 11, 2021 - When you clone a Git repo, the original repo is automatically added as a remote on the clone. You can name remote repos whatever you want, but the default used when cloning is origin, because it represents the repo this clone originated from. Because of this default, you'll see a remote repo named origin on most Git repos you work with.
🌐
TecAdmin
tecadmin.net › git-add-remote-repository
`git remote add origin` - A Practical Guide – TecAdmin
April 26, 2025 - Replace ‘origin’ with the name you want to assign to the remote repository, and replace ‘https://github.com/user/repo.git’ with the actual remote repository URL. The name ‘origin’ is a convention for the default remote repository, but you can choose any name that suits your needs. After adding the remote repository, it’s essential to verify that it’s correctly connected to your local repository.
🌐
Gitbybit
gitbybit.com › course › gitbybit-part1 › 07 › 0003-adding-github-repository-as-remote
Adding GitHub repository as a remote
To add a remote, we use the git remote add command, followed by the name of the remote and the URL of the repository.
🌐
Stack Abuse
stackabuse.com › git-add-new-remote-to-a-repo
Git: Add New Remote to a Repo
June 19, 2019 - $ git remote add origin [email protected]:scottwrobinson/camo.git
🌐
JetBrains
jetbrains.com › guide › java › tutorials › creating-a-project-from-github › adding-updating-remotes
Adding and Updating Remotes - JetBrains Guide
February 17, 2023 - Press ⏎ (macOS) / Enter (Windows/Linux) on this option to display the Git Remotes dialog. Here we can see the remote that we originally cloned this project from, this is our fork of the intellij-samples repository.
🌐
CloudBees
cloudbees.com › blog › git-remote-add
Follow These Steps To Add a New Remote To Your Git Repo
The first command adds all your project files to Git, while the second command creates a commit. At this point, you have initialized Git in your project and made your first commit. Commits are like save points in a video game. Git does not auto-save changes to your project. Instead, changes are saved in commits. In the previous step, we created a new local Git repo. Now let's create a remote repo and retrieve the Git URL for the remote repo.
🌐
KodeKloud
kodekloud.com › blog › change-remote-origin-in-git
How to Change Remote Origin in Git
November 5, 2025 - Non-Destructive Change: Updating the remote origin does not affect your codebase, branches, or commit history - only the destination changes. Quick Verification: Use git remote -v before and after updating to confirm your repository now points to the correct remote.
🌐
Quora
quora.com › What-does-git-remote-add-origin-do
What does 'git remote add origin' do? - Quora
Answer (1 of 3): You can share code with other developers through services like GitHub, Bitbucket and GitLab You create a remote repository on one of these services and then you can push the commits you make on your computer to that remote repository. To tell the git repository on your computer...
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git remote add explained (with examples, mistakes & fixes)
git remote add Explained (With Examples, Mistakes &amp; Fixes) | GoLinuxCloud
January 24, 2026 - Git remote add is a git command that enables developers to work on a central remote repo by creating remote duplicates. Remote add command serves as a means through which collaborators for a project can independently make commits for a shared ...