You can not call remote set-url origin
just after git init
, Because the git remote set-url
command will not create origin, but it changes an existing remote repository URL.
so the command git remote set-url
will only work if you've either cloned the repository or manually added a remote called origin.
you can check remote with command git remote -v
it will show remote url after name, or if this command gives error like fatal: Not a git repository (or any of the parent directories): .git
then the repository not exists, so you have to add origin with command git remote add
1. git remote add
This command is used to add a new remote, you can use this command on the terminal, in the directory of your repository.
The git remote add command takes two arguments:
- A remote name, for example, origin
- A remote URL, for example, https://github.com/user/repo.git
For example:
git remote add origin https://github.com/user/repo.git
2.git remote set-url
The git remote set-url command changes an existing remote repository URL.
The git remote set-url command takes two arguments:
- An existing remote name. For example,
origin
or upstream
are two common choices.
- A new URL for the remote
For example you can change your remote's URL from SSH to HTTPS with the git remote set-url
command.
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
you can verify that the remote URL has changed, with command git remote -v
.
note: "origin" is a convention not part of the command. "origin" is the local name of the remote repository. you can use any name instead of "origin".
For example:
git remote add myorigin [email protected]:user/repo.git
git remote set-url myorigin https://github.com/user/repo.git
References from github: remote add, remote set-url