error: No such remote: 'upstream' means the remote name you passed to a git remote command is not configured in this repository. Run git remote -v to see the names that exist, then use one of them, or add the missing one with git remote add upstream <url>.

The name is only a local nickname for a URL. A tutorial that says upstream assumes you added it earlier; a fresh clone has only origin.

The error

PS> git remote remove upstream
error: No such remote: 'upstream'

PS> git remote rename upstream up
error: No such remote: 'upstream'

PS> git remote set-url upstream ..\b6-remote.git
error: No such remote 'upstream'

git remote rm printed the same line as remove, and git remote get-url upstream the same as set-url, without the colon. All of them exited with code 2.

Why it happens

Remotes live in the repository's own configuration as named entries. The git remote subcommands that change or read one entry look the name up and stop when it is not there. The repository in the test had only origin:

PS> git remote -v
origin	..\b6-remote.git (fetch)
origin	..\b6-remote.git (push)

The usual causes are a typo, following fork instructions that expect an upstream remote you never added, or running the command in a different clone from the one you configured. Commands that talk to the network word the same mistake differently, because they first try the name as a path or URL:

PS> git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

git push upstream main and git remote show upstream printed the same.

The fix

Add the remote. After that, the two commands run again in the test, set-url and fetch, both worked:

PS> git remote add upstream ..\b6-remote.git
PS> git remote set-url upstream ..\b6-remote.git
PS> git fetch upstream
From ..\b6-remote
 * [new branch]      main       -> upstream/main

Use the real repository URL instead of the test's local path. If you only mistyped the name, use the one git remote -v lists instead; set-url changes an existing remote's address and did not create one here, which is why it failed first and worked after the add.

How it was reproduced

Git for Windows 2.45.2 on Windows 11, Windows PowerShell 5.1, in a throwaway repository whose only remote, origin, pointed at a local bare repository. remove, rm, rename, set-url and get-url for upstream exited with code 2; fetch, push and remote show exited with 128. After git remote add upstream, set-url and fetch succeeded.

Frequently asked

How do I fix error: No such remote in git?
Run git remote -v to list the remotes that exist. Use one of those names, or add the missing remote with git remote add followed by the name and the URL.
How do I add an upstream remote in git?
Run git remote add upstream followed by the URL of the original repository, then git fetch upstream. Check it with git remote -v.
Why does git remote set-url say No such remote?
set-url only changes the address of a remote that already exists. Add the remote first with git remote add, then set-url works.

More decoded errors in the Fixes category. For the "does not appear to be a git repository" message with origin, see fatal: origin does not appear to be a git repository.