You ran git remote add origin git@github.com:you/repo.git and Git snapped back:
error: remote origin already exists.That's it. Git isn't broken. It just refuses to clobber an existing name. The culprit here is almost always one of two things: you cloned the repo first (clones auto-create origin), or you already ran the same command earlier and forgot.
Pick the fix that matches what you actually want. Stop when it works.
Step 1 — The 30-second fix: just change the URL
If origin exists but points somewhere wrong, don't delete it. Just overwrite the URL.
git remote set-url origin git@github.com:you/newrepo.gitVerify:
git remote -vYou'll see fetch and push lines. If both show your new URL, you're done. This is the right answer 80% of the time. It's non-destructive, it doesn't touch your branches, and it doesn't care whether you cloned or added.
Real-world trigger: you cloned a forked repo, then decided to push to your own fork. The fork's origin is already there. Set-url handles it in one line.
Step 2 — The 5-minute fix: remove and re-add
Sometimes the remote is pointing at something weird — a dead host, a renamed org, an SSH URL you can't auth against. If you'd rather start clean:
- Check what's there:
git remote -v - Remove it:
git remote remove origin - Add the correct one:
git remote add origin <url> - Confirm:
git remote -v
Don't use git remote rm origin if you have local branches tracking it — you'll lose the upstream tracking relationship. You'll need to re-set upstream with git push -u origin main after.
If you have other remotes besides origin (say, upstream for the original project and origin for your fork), git remote remove origin is safe — it only nukes the one you name.
Step 3 — The 15-minute fix: you actually need multiple remotes
Here's where people get stuck. They want origin AND another remote with a different name, but they keep typing add origin twice. Git doesn't allow two remotes with the same name. Ever.
Name them differently:
git remote add upstream git@github.com:original-org/repo.git
git remote add origin git@github.com:yourname/repo.gitNow you can fetch from upstream and push to origin. This is the standard fork workflow. If you've been trying to add origin twice for different hosts, that's your real problem.
To rename an existing remote instead:
git remote rename origin old-origin
git remote add origin git@github.com:you/new.gitCommon screwups I see weekly
- Wrong SSH URL — you copied HTTPS but your key is SSH. Check with
ssh -T git@github.com. - Case sensitivity — GitHub org names are case-insensitive in URLs but Git itself stores the string as-is. Typos hide here.
- Submodule confusion — if this is a submodule, the remote is managed by the parent repo. Don't hand-edit it. Run
git submodule syncinstead. - Leftover from a failed clone — a half-cloned repo can leave a stale
originpointing at a temp dir. Remove and re-add.
What NOT to do
Don't git push -f to "reset" things. Don't delete your .git folder and re-clone unless you've got nothing local worth keeping. Don't edit .git/config by hand when git remote set-url exists — the file is fine but you'll typo the format and spend 20 minutes debugging your own edit.
Quick rule: if origin exists but points wrong → set-url. If you need a second remote → name it something else. If origin is a corpse → remove and re-add.Checklist before you push
| Command | What it tells you |
|---|---|
git remote -v | Every remote and its URLs |
git branch -vv | Which local branch tracks which remote |
git status | Whether your branch has an upstream set |
Once git remote -v shows the URL you want, run git push -u origin main (or master). The -u sets upstream so future pushes are just git push.
That's the whole thing. The error sounds scary. It isn't. Git is just being literal — a remote named origin already exists, so it won't create another. Rename it, repoint it, or remove it. Pick one and move on.