Context
A common dotfiles trick is to fetch pull-request branches in every repository by putting the refspecs in the global gitconfig:
[remote "origin"] fetch = +refs/pull/*/head:refs/remotes/origin/pr/head/* fetch = +refs/pull/*/merge:refs/remotes/origin/pr/merge/*Insight
Git reads every config level and merges them, so every repository now has a remote named origin, even a freshly initialised one with no remote. It has fetch rules but no URL:
git init demo && cd demogit remote -v# origin <- no URLThat surprises scripts, agents and people who read git remote -v or git config remote.origin.* to decide whether a repo already has a remote.
What I checked (git 2.55): git remote add origin <url> still works. It writes the URL and the default +refs/heads/*:refs/remotes/origin/* refspec into .git/config, and the global pull-request refspecs keep applying on top. Not tested: tools that refuse to create a remote that “already exists”, such as gh repo create --source . --remote origin. When in doubt, set the URL in the repository’s own config instead:
git config remote.origin.url <url>git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'Find where a phantom remote comes from:
git config --show-origin --get-regexp '^remote\.'Docs
A docs check did not find this behaviour described on these pages (no claim beyond them):