【问题标题】:Failed to connect to remote repository无法连接到远程存储库
【发布时间】:2019-06-21 20:53:15
【问题描述】:

我不小心从远程开发分支切换到本地开发,现在无法切换回来。

当我尝试:

 git fetch origin/master

我明白了

fatal: 'origin/master' 似乎不是 git 存储库。 致命:无法从远程存储库读取。

我也试过了:

git checkout origin/master

我得到了:

错误:pathspec 'origin' 与 git 已知的任何文件都不匹配。 错误:pathspec 'master' 与 git 已知的任何文件都不匹配。

我用 git remote -v 检查了我的来源的 url 在那里。同样在配置文件中显示正确的 url

remote.dev.url=https://'my_origin_url'.git
remote.dev.fetch=+refs/heads/*:refs/remotes/dev/*
remote.dev.pushurl=https://'my_origin_url.git
branch.dev.remote=dev
branch.dev.merge=refs/heads/dev
remote.origin.url=https://'my_origin_url'.git/
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

我试过了:

git reset --hard origin/master

结果是:

致命:模棱两可的参数“来源/主”:未知的修订或路径 不在工作树中。

我怎样才能回到我的原始分支?

【问题讨论】:

  • 这两个独立的pathspec ... 错误表明您必须运行git checkout origin master。 Git 在这里可能会非常混乱:什么时候应该使用origin,什么时候应该使用master,什么时候应该使用origin/master,什么时候应该使用origin master?答案都不同!
  • 是的,我可能确实跑过git checkout origin master :(你能告诉我下一步该怎么做吗?
  • 远程repo连接有问题,已解决并成功切换到origin分支,谢谢指教

标签: git bitbucket git-remote


【解决方案1】:

当你获取时,你应该只指定远程,而不是分支:

git fetch origin

结帐大师:

git checkout master

由于 master 看起来还不是沙箱中的本地分支,它应该会自动重新创建,并以 origin/master 作为其上游,这正是您想要的。

如果它是使用dev/master 作为上游创建的,则需要明确设置其上游分支。

选项1:在创建分支时明确指定上游:

git checkout -b master -t origin/master

选项2:事后更新上游,如果分支存在错误的上游:

git branch -u origin/master master    

【讨论】:

  • 对于选项 2,我得到 error: the requested upstream branch 'origin/master' does not exist。对于选项 1,我也无法获取,我得到 fatal: unable to access 'https://my_origin_url.git/': Failed connect to my_origin_url:443; Connection refused
  • 如果git fetch 因连接被拒绝而失败,您将需要提供您的凭据,这与您在初始git clone 时必须提供的方式相同。您可能需要在 git 配置中更新您的 ssh 密钥或凭据。在这里查看更多信息:stackoverflow.com/questions/35942754/…
  • Connection refused 看起来更像是网络问题或远程系统上的配置问题。您应该能够通过GIT_CURL_VERBOSE=1 git fetch origin 看到更多细节。
猜你喜欢
  • 2014-08-01
  • 2013-12-14
  • 1970-01-01
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
  • 2013-04-13
  • 2018-06-18
  • 1970-01-01
相关资源
最近更新 更多