我在Github上有一个私人存储库,用于我正在进行的一个项目。到目前为止,我只在家里的台式机上工作,但我刚刚买了一台笔记本电脑,我正在尝试设置它,以便我可以在任何一台电脑上工作,并进行推/拉更改。

我在我的Github账户上为笔记本电脑添加了一个新的SSH密钥,并且成功地克隆并更改了我设置的公共测试回购。但是,我不能克隆私人回购。为了克隆私有回购,我需要在命令行中做什么特别的事情吗?我是否需要为我的笔记本电脑设置一个新的GitHub帐户,并将自己设置为合作者?

我使用的命令是git clone git://github.com/username/reponame.git


当前回答

这招对我很管用:

Git克隆https://username@github.com/username/repo_name

其他回答

这招对我很管用:

Git克隆https://username@github.com/username/repo_name

如果你想在Dockerfile中实现它,下面几行可以帮助你。

ARG git_personal_token
RUN git config --global url."https://${git_personal_token}:@github.com/".insteadOf "https://github.com/"
RUN git clone https://github.com/your/project.git /project

然后我们可以使用下面的参数进行构建。

docker build --build-arg git_personal_token={your_token} .

私有克隆url的形式为git@github.com:username/repo.git -也许你需要使用git@而不是git://?

url是只读的,看起来私有回购不允许这种形式的访问。

首先,确保您有SSH密钥或在以下位置生成一个: https://help.github.com/articles/generating-ssh-keys/

一旦你有了你的密钥,你必须把它添加到你的github帐户: https://github.com/settings/ssh

对于Windows用户,作为管理员运行git bash非常有用。

现在,克隆应该适用于私有存储库(repo),而无需输入用户名和密码。

我使用Android Studio从GitHub私有存储库和双因素身份验证(2FA)克隆项目。我在lzl124631x的答案中创建了一个个人令牌。

然后我用这样的url克隆了repo: https://YourGitHubUsername:YourGeneratedPersonalToken@github.com/YourRepoPath.git