简体   繁体   English

ssh -vT git@github.com工作正常,代理位于github ssh密钥中。 问题出在哪里?

[英]`ssh -vT git@github.com` works fine, and agent is in github ssh keys. Where is the issue?

I just bought a new machine, and I'm working on a new github repo. 我刚买了一台新机器,正在开发一个新的github存储库。 I clone it into my machine using 我将其克隆到我的机器上

git clone git@github.com:<username>/<exact-repo-name>.git

and it clones fine: 它克隆很好:

Cloning into '<exact-repo-name>'...
remote: Counting objects: ###, done.
remote: Total ### (delta 0), reused 0 (delta 0), pack-reused ###
Receiving objects: 100% (###/###), ### KiB | 0 bytes/s, done.
Resolving deltas: 100% (###/###), done.
Checking connectivity... done.

And, I add all of the remote branches locally by doing: for remote in git branch -r; do git checkout -b $remote; done 并且,我通过执行for remote in git branch -r; do git checkout -b $remote; done本地添加所有远程分支: for remote in git branch -r; do git checkout -b $remote; done for remote in git branch -r; do git checkout -b $remote; done

Then, when I try to pull from any of the branches, using 然后,当我尝试从任何分支中拉出时,使用

git pull origin/<branch-name> 

I get the ever-so-common error: 我收到了一个非常常见的错误:

origin/<branch-name> does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

So, I go through all of the steps: 因此,我完成了所有步骤:

ssh -vT git@github.com
ssh-add -l
eval "$(ssh-agent -s)"

These all succeed, and I check the output of ssh-add -l and I see that it is in the list ssh keys on my github account. 这些都成功了,我检查了ssh-add -l的输出,发现它在我的github帐户的列表ssh项中。 I go into Settings -> ssh keys, and I see the agent there. 我进入设置-> ssh键,在那里看到代理。

Are there certain user permissions that are on top of those for ssh ? 除了ssh ,还有某些用户权限吗?

I agree with @Felix that this most likely is not an SSH problem, though it might be masquerading as this. 我同意@Felix的观点,尽管这可能是伪装的,但这很可能不是SSH问题。 Instead, I think you have a problem with your path. 相反,我认为您的路径有问题。 You can try running git clone like this: 您可以尝试像这样运行git clone

git clone https://username@github.com/username/exact-repo-name.git

Here the username is your GitHub username. 这里的username是您的GitHub用户名。 Git will prompt you for a password so you don't have to enter it as plain text. Git会提示您输入密码,因此您不必以纯文本形式输入密码。 Please read this SO article for more information. 请阅读这篇SO文章以获取更多信息。

It's probably not an ssh issue, as an ssh problem would normally result in a message like 这可能不是ssh问题,因为ssh问题通常会导致显示如下消息

fatal: The remote end hung up unexpectedly

Most likely it's a path problem: either you have an extra slash or space in the remote path (or if there's supposed to be a space, you're missing quotation marks in your command line), or some letter is the wrong case. 最有可能是路径问题:远程路径中有多余的斜线或空格(或者如果应该有空格,则命令行中缺少引号),或者大小写错误。 Double-check the rest of the URL. 仔细检查URL的其余部分。 It could also be exactly what it says, a permissions problem -- are you sure you're connecting as the right user for this repository? 这也可能正是它所说的,是一个权限问题-您确定要以该存储库的正确用户身份进行连接吗?

Edit: from your added details, it looks like you're just getting the syntax of the pull command mixed up. 编辑:从您添加的详细信息来看,您似乎只是弄混了pull命令的语法。 Does it work if you do this?: 如果这样做,是否有效?:

git checkout <branch-name>
git pull # Edit: don't do this without reading all of 'git help pull'

? Also, does git fetch --all work? 另外, git fetch --all可行吗? ( git pull is just git fetch followed by git merge .) git pull只是git fetch然后是git merge 。)

Further edit: I can reproduce your error; 进一步编辑:我可以重现您的错误; it is a command syntax problem. 这是命令语法问题。 Here are more examples: 这里有更多示例:

"source" is a git repository in a local folder; “源”是本地文件夹中的git存储库; I clone it into a folder called "dest": 我将其克隆到一个名为“ dest”的文件夹中:

$ git clone source dest
$ cd dest

Now I do the git branch command in your for loop: 现在,我在您的for循环中执行git branch命令:

$ git branch -r
  origin/HEAD -> origin/master
  origin/branch1
  origin/branch2
  origin/master

I would expect that first line to cause problems, since that would result in these commands being run in your for loop: 我希望第一行会引起问题,因为这将导致这些命令在for循环中运行:

git checkout -b "origin/HEAD"
git checkout -b "->"
...

(Note that your example is missing backticks around `git branch -r` , so if what you posted is literally what you're running, you'll end up with branches called "git", "branch", and "-r", which would really not be what you want... if you had trouble putting backticks into inline code blocks, see https://meta.stackexchange.com/questions/55437/how-can-the-backtick-character-be-included-in-code ) (请注意,您的示例缺少`git branch -r`周围的反引号,因此,如果您发布的内容实际上是您正在运行的内容,则最终将得到名为“ git”,“ branch”和“ -r”的分支,这实际上不是您想要的...如果您难以将反引号放入内联代码块中,请参阅https://meta.stackexchange.com/questions/55437/how-can-the-backtick-character-be-包含在代码中

Then if I try your pull command, I get the same error as you: 然后,如果我尝试使用pull命令,则会收到与您相同的错误:

$ git pull origin/branch1
fatal: 'origin/branch1' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

This is because git pull takes the remote repository name (origin) and the remote branch name (branch1) as two separate parameters, separated by a space. 这是因为git pull将远程存储库名称(origin)和远程分支名称(branch1)作为两个单独的参数,并用空格分隔。 So this works: 所以这工作:

$ git pull origin branch1
From /tmp/source
 * branch            branch1    -> FETCH_HEAD
Already up-to-date.

But, that's probably not quite what you want, because it sounds like you wanted to create a bunch of local branches to track the same named branches on origin (eg you want a local branch named "branch1" that tracks "origin/branch1"). 但是,这可能并不是您想要的,因为您似乎想创建一堆本地分支以跟踪起源上的相同命名分支(例如,您想要一个名为“ branch1”的本地分支来跟踪“ origin / branch1”) 。 Your local branch creation commands didn't include setting up tracking, so what you've actually got is a local branch called "origin/branch1" and a branch on remote repository "origin" also called "branch1", ie after running your for loop, the output of git branch -a is: 您的本地分支创建命令不包括设置跟踪,因此您实际得到的是一个名为“ origin / branch1”的本地分支和一个远程存储库“ origin”上的一个分支,也称为“ branch1”,即在运行您的for循环, git branch -a的输出是:

$ git branch -a
  master
  origin/HEAD
  origin/branch1
* origin/branch2
  origin/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/branch1
  remotes/origin/branch2
  remotes/origin/master

...So there are two branches called "origin/branch1", and the only thing that differentiates them is that in one case, the repository is your local one and the branch's literal full name is "origin/branch1", and in the other case, the repository is the remote one (named origin) and the branch's literal full name is "branch1", which is notated as "origin/branch1" -- this will probably be very confusing to work with (and in some commands, git will complain and say, "origin/branch1 is ambiguous" and you'll have problems). ...因此有两个分支称为“ origin / branch1”,唯一使它们与众不同的是,在一种情况下,存储库是您的本地分支,分支的字面全名是“ origin / branch1”,而在在另一种情况下,存储库是远程存储库(命名为origin),而分支的字面全名是“ branch1”,记为“ origin / branch1”-使用它可能会非常混乱(在某些命令中, git会抱怨说“ origin / branch1不明确”,您会遇到问题)。

Note also that each of the new branches your for loop created is actually just a copy of master (or whatever the default/selected branch was on origin), because you didn't specify a remote branch for them to start from. 还请注意,您的for循环创建的每个新分支实际上只是master的副本(或原始的任何默认/选定分支),因为您没有为它们指定从远程分支开始。 That is, in your clone command, your local repository was set up with one branch selected (probably master). 也就是说,在您的克隆命令中,您选择了一个分支(可能是主分支)来设置本地存储库。 You then told git "make new branch from where I am now" for each line in your for loop, so each of those new branches, despite having all the different names of the branches on remote, are references to the first branch selected with your clone. 然后,您为for循环中的每一行告诉git“从现在所在的位置创建新分支”,因此尽管这些新分支中的每一个都在远程上具有所有不同的名称,但它们都是对您选择的第一个分支的引用克隆。 This is probably not what you wanted. 这可能不是您想要的。

I think what you actually wanted was this command, run for each remote branch: 我认为您真正想要的是为每个远程分支运行的命令:

$ git checkout --track origin/branch1
Branch branch1 set up to track remote branch branch1 from origin.
Switched to a new branch 'branch1'

Actually, if you've just done a fresh clone, a git checkout branch1 [without the -b ] will have the same effect I think -- since there is no local branch called branch1, git will look for one in the repository you cloned from and set up tracking if it finds one. 实际上,如果您刚刚进行了新的克隆,则git checkout branch1 [不带-b ]会产生与我相同的效果-由于没有名为branch1的本地分支,因此git会在您克隆的存储库中查找一个分支从并设置跟踪(如果找到)。

...So I guess what this whole post boils down to is: ...所以我想这整个帖子可以归结为:

  • Leave out the -b in your initial checkout commands 在初始签出命令中-b
  • Use a space instead of a slash in your pull command 在您的pull命令中使用空格而不是斜杠

:) :)

See https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches and the output of git help pull for more about remote tracking and pulling; 参见https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches ,而git help pull的输出可获取有关远程跟踪和拉git help pull的更多信息。 some of it is a bit subtle (even more so than all the caveats I mentioned :) ). 其中有些有些微妙(甚至比我提到的所有警告还多:))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM