How to recover from a state where a remote cannot be fully deleted?

51 Views Asked by At

I have run git remote remove origin, but the remote origin doesn't get fully removed.

Now when I run git remote -v, it lists origin, but does not give any URL next to it.

All other git remote commands will tell me error: No such remote: 'origin'.

There is no mention of origin in .git/config.

I have tried re-adding an origin remote, then fetching from it, then removing it again. These commands are all successful but they leave me in the same state.

Any ideas how I can make git forget about this origin remote?

[Background: The repo uses git-lfs, and I regularly get smudge filter lfs failed errors when merging/rebasing from upstream (the main company repo), and the only workaround I have found is to delete all remotes, re-add upstream, fetch, then do the merge/rebase before adding back any additional remotes. This stubborn corrupt remote is preventing this process from working.]

2

There are 2 best solutions below

0
phd On BEST ANSWER

This could be from the global ~/.gitconfig. Find it out with

git config --get-regexp --global "remote\.*"

or

git config --list --show-origin | grep -Fw origin

PS. Hm, hmm, --show-origin is about a different kind of "origin". :-)

0
stackspace On

git stores all its metadata in the .git subdirectory of your repo. If we can find the right place to edit in that directory, we should be able to fix your repo.

You can find some information about how information is stored in the git book: https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain

After some exploring, I recommend looking in a couple places:

  • .git/config: has a section for each remote. If there is a section for origin, delete it.
  • .git/refs/remotes: has a directory for each remote, with a file for each branch in that remote. If there is a directory called origin, delete it.

The actual repository data is stored in .git/objects. As long as you don't start deleting files in that directory you won't lose your repository contents :)