Nanfeng

Notes on software development, code, and curious ideas

Git remote origin already exists: Inspect, Update or Replace the Remote

After cloning someone else’s repository and adapting the code, you may see this error when trying to add your own remote:

1
error: remote origin already exists.

First inspect the current remotes:

1
git remote -v

If you want to keep the existing origin name and only change its URL, the simplest option is:

1
git remote set-url origin https://gitee.com/your-account/your-repository.git

Alternatively, remove and recreate it:

1
2
git remote remove origin
git remote add origin https://gitee.com/your-account/your-repository.git

Then push the current branch:

1
git push -u origin HEAD

Using HEAD avoids assuming that the branch is named master; modern repositories often use main or another default branch.

+