git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to remove invalid remote repository

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jun 5, 2007, 20:18 UTC
Message-ID
<alpine.LFD.0.98.0706051308090.4921@woody.linux-foundation.org>
In-Reply-To
<8A00BB77B01133479F4A56D932A1132202906FD8@EX-401.mail.navisite.com>
On Tue, 5 Jun 2007, Matt Seitz wrote:
>
> I mistakenly entered the wrong directory name for "git remote add" (I
> entered the working tree directory name instead of the ".git" directory
> name). 

Now, that should be fine. You don't have to add the .git name, git will figure it out on its own.

> So "git fetch" fails with:
> 
> fatal: 'origin': unable to chdir or not a git archive
> fatal: The remote end hung up unexpectedly

Well, this is because you apparently didn't call the remote "origin", but something else. So when you do

	git fetch

without giving any remote name at all, git will *default* to using "origin" as a remote, but since no such remote name exists, it will try to use that remote as a pathname (which is admittedly a bit silly, but git doesn't know that), and so what happened was that it was trying to fetch from the git repository "origin", but no such git repository existed, and thus it says:

	fatal: 'origin': unable to chdir or not a git archive

In fact, the remote name you added seems to be "root-etc", juding from your config file (which I've recreated here by looking at your "git config -l" output - things like whitespace may be off):

	[core]
		repositoryformatversion=0
		filemode=true
		bare=false
		logallrefupdates=true
	[gui]
		geometry=811x591+781+0 107 172
	[remote "root-etc"]
		url=/root/git/etc
		fetch=+refs/heads/*:refs/remotes/root-etc/*
Show 7 quoted lines
> So, I tried removing the remote tracking branches:
> 
> git branch -d -r root-etc/master
> 
> But that failed with:
> 
> error: remote branch 'root-etc/master' not found.

The easiest way to remove the remote is _literally_ by just editing the ".git/config" file. It's not magic, and the syntax really is as trivial as it looks, and it's perfectly ok to just fire up an editor and fix it up.

In this case, the easiest fix is to not delete that remote entry at all (it's a fine entry, afaik), but you have to tell git that your local "master" branch should track it. You do that by just adding

	[branch "master"]
		remote = root-etc
		merge = refs/heads/master

which tells git that when you are on the "master" branch, and do a "git fetch", it should fetch from that "root-etc" remote (and if you doa "pull", which implies also merging, it should merge the "refs/heads/master" branch from that remote into your local master).

Show 7 quoted lines
> So I then tried recreating the remote reference:
> 
> git remote add root-etc /root/git/etc/.git
>
> But that failed with:
> 
> remote root-etc already exists

Right. It already does, because you already have it, and your previous add already worked. The only issue is that since you didn't tell that your current branch should be hooked up with that particular remote, so git ended up using the default (which is called "origin", not "root-etc").

		Linus
Previous: Jan HudecNext: Matt Seitz
Message 3 of 4 in “How to remove invalid remote repository”
  1. Matt SeitzJun 5, 2007
  2. Jan HudecJun 5, 2007
  3. Linus TorvaldsJun 5, 2007
  4. Matt SeitzJun 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.