git Git忘记了我从/推送到的远程存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6905862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:28:45  来源:igfitidea点击:

Git has forgotten the remote repository I fetch from / push to

gitrepository

提问by hamishmcn

This morning I went to do a git fetch and got the following error:

今天早上我去执行 git fetch 并收到以下错误:

fatal: No remote repository specified. Please, specify either a URL or a remote name from which new revisions should be fetched.

致命:未指定远程存储库。请指定一个 URL 或一个远程名称,从中可以获取新的修订版本。

This used to work fine. It looks like git has forgotten the link between (all) my branches and the repository.
Typing git remote -vdoesn't return anything.
It was working at the end of last week, and the only thing that I can think of that I have changed was installing the latest GitExtensions release. However right now I am more worried about whether there is some way I can get back the repository information.
Any ideas?

这曾经工作得很好。看起来 git 忘记了(所有)我的分支和存储库之间的链接。
键入git remote -v不会返回任何内容。
它在上周末开始工作,我能想到的唯一改变是安装最新的 GitExtensions 版本。但是现在我更担心是否有某种方法可以取回存储库信息。
有任何想法吗?

Update:
My .git/config file was empty. Although I don't know the cause, I was able to remote desktop to another computer in the company and retrieve the "remote" section of its config.
I have updated my config file, and so far it looks like it is working :-)

更新:
我的 .git/config 文件是空的。虽然我不知道原因,但我能够远程桌面到公司的另一台计算机并检索其配置的“远程”部分。
我已经更新了我的配置文件,到目前为止看起来它正在工作:-)

Update 2: I have also needed to relink the branches to the origin via:

更新 2:我还需要通过以下方式将分支重新链接到原点:

git config branch.develop.remote origin
git config branch.develop.merge refs/heads/develop

etc

等等

回答by Kit Ho

  1. You can take a look on .git/config and configure it.

  2. You can also make your local branch track back your remote branch by typing

    git branch --set-upstream <localbranch> <remotebranch>

  1. 您可以查看 .git/config 并对其进行配置。

  2. 您还可以通过键入使您的本地分支跟踪您的远程分支

    git branch --set-upstream <localbranch> <remotebranch>

When you type git fetchthe local branch will fetch codes from those tracking remote branch.

当您键入时git fetch,本地分支将从那些跟踪远程分支中获取代码。

回答by drrd

Seems like a very old question, but want to update to Kit Ho's answer with slight modification. Might be useful for someone.

似乎是一个很老的问题,但想稍微修改一下 Kit Ho 的答案。可能对某人有用。

git branch --set-upstream <localbranch> <remotebranch> 

is deprecated as of git version 1.9.2. This is the correct syntax now,

自 git 版本 1.9.2 起已弃用。这是现在正确的语法,

git branch --set-upstream-to=<upstream>

An example would be,

一个例子是,

git branch --set-upstream-to=originremote/testbranch

回答by Charles Ma

Remote information should be stored in the .git/config file, check that file and see if it's corrupted. If it is you might have to re-add every remote you had before or do a clean checkout, if it is there, there might be a bug in the GitExtension release...

远程信息应该存储在 .git/config 文件中,检查该文件并查看它是否已损坏。如果是这样,您可能必须重新添加以前拥有的每个遥控器或进行干净的结帐,如果存在,则 GitExtension 版本中可能存在错误...