Overview
The error "fatal: No such remote: origin" means your repository has no remote named origin, or the name is misspelled in your command or config. This guide shows fast, practical fixes for DevOps workflows (local, CI/CD, submodules, and worktrees).
Quickstart (3 steps)
- Verify remotes:
- Run:
git remote -v— if empty or noorigin, proceed.
- Run:
- Add or fix
origin:- Add:
git remote add origin <url> - Or rename:
git remote rename <current> origin
- Add:
- Set upstream and push:
git branch -M maingit push -u origin main
Minimal Working Example
This creates a repo, triggers the error, then fixes it.
# 1) Create a repo with a commit
mkdir demo && cd demo
git init
printf "hello\n" > README.md
git add README.md
git commit -m "init"
# 2) Trigger the error by pushing to a non-existent remote name
git push origin main # -> fatal: No such remote: 'origin'
# 3) Fix: add the correct remote and push
# Use HTTPS or SSH URL as appropriate
git remote add origin https://github.com/yourorg/yourrepo.git
git branch -M main
git push -u origin main
# 4) Confirm
git remote -v
git remote show origin
Diagnose the cause
- Confirm you're inside a Git repo:
git rev-parse --is-inside-work-treeshould printtrue.
- List remotes:
git remote -v— check iforiginexists and has a URL.
- Check current branch tracking:
git branch -vv— look for[origin/<branch>]after your branch name.
- Inspect repository config:
git config --show-origin --get-regexp '^remote\..*'— shows where remotes are defined.- Or open
.git/configand look for a[remote "origin"]section.
- For submodules/worktrees/CI:
- Submodules:
cdinto the submodule path and repeat steps. - Worktrees: ensure you're in a valid worktree root (
git worktree list). - CI: verify the checkout step populates remotes (e.g., avoid
--no-single-branchor shallow config that omits origin if your tool modifies remotes).
- Submodules:
Common scenarios and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
git remote -v shows nothing | No remotes configured | git remote add origin <url> |
You used git push origin main but only upstream exists | Remote name mismatch | git remote rename upstream origin |
origin exists but URL is wrong | Moved repo or changed protocol | git remote set-url origin <url> |
| Submodule push fails with error | Running commands in parent repo | cd path/to/submodule && git remote -v && git push |
| CI job fails despite local success | Checkout step didn’t configure remotes | Configure CI checkout to fetch with remotes; or add git remote add origin <url> in the job |
Worktree lacks origin | Config stored in main repo; mispointed GIT_DIR | Run from the worktree; avoid overriding GIT_DIR; ensure .git file points correctly |
Fix recipes
- Add
origin(new or existing local repo):
git remote add origin https://github.com/org/repo.git
# or SSH
git remote add origin [email protected]:org/repo.git
- Rename an existing remote to
origin:
git remote rename upstream origin
- Change the URL of
origin:
git remote set-url origin https://github.com/org/repo.git
- Recreate a broken
originentry:
git remote remove origin
git remote add origin <url>
- Set upstream for your branch (avoids having to specify remote/branch every time):
git branch -M main
git push -u origin main
- Verify after fixing:
git remote -v
git remote show origin
Submodules and nested repos
- Each submodule has its own
.gitdirectory and remotes.cdinto the submodule before addingorigin. - To fix all submodules:
git submodule foreach 'git remote -v || true'
# If missing in a submodule:
# git submodule foreach 'git remote add origin <url-for-that-submodule>'
Worktrees
- Worktrees share the same object store and often shared config.
- If a worktree reports the error, ensure:
- You are in the worktree root (contains a
.gitfile pointing to the main repo). - You didn’t set
GIT_DIRto the wrong path.
- You are in the worktree root (contains a
CI/CD notes
- Some CI runners perform a shallow fetch with a detached HEAD and may rename or omit remotes.
- Remedies:
- Add
git remote -vin the job to debug. - Explicitly add/reset the remote:
- Add
git remote remove origin 2>/dev/null || true
git remote add origin "$CI_REPOSITORY_URL"
- Set upstream before pushing tags or branches:
git branch -M "$CI_DEFAULT_BRANCH"
git push -u origin "$CI_COMMIT_REF_NAME"
Pitfalls
- Remote names are case-sensitive:
Origin≠origin. git remote add originfails iforiginalready exists. Useset-urlorrename.- Using a wrong URL schema (SSH vs HTTPS) won’t cause this error, but will cause auth failures later.
- Running commands from a parent directory of the repo won’t show this error; you’ll see "not a git repository" instead.
- In monorepos with nested Git repos, ensure you’re in the correct
.gitroot.
Performance notes
- All remote configuration commands are local and instant; only
fetch/pushhits the network. - Avoid unnecessary fetches when fixing the error; prefer
git remote -vandgit configqueries first. - In CI, use shallow clones for speed, but ensure remotes remain configured if you need to push.
FAQ
Why did
origindisappear?
Someone removed or renamed it, or you cloned via a tool that overrides remotes.Do I have to name it
origin?
No, but many tools default toorigin. If you choose another name, use it consistently.How do I see which branches track
origin?git branch -vvshows tracking info;git remote show originlists remote branches.Can I have multiple remotes?
Yes. Add more withgit remote add <name> <url>and push/fetch using that name.Does deleting
.git/confighelp?
No. Edit it carefully or usegit remotecommands to avoid corrupting repo settings.