首页 文章

克隆私人Github回购

提问于
浏览
144

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

我为笔记本电脑的Github帐户添加了一个新的SSH密钥,并成功克隆并更改了我设置的公共测试仓库 . 但是,我无法克隆私人仓库 . 在命令行中我需要做些什么特别的事情才能克隆私人仓库?我是否需要为笔记本电脑设置一个新的GitHub帐户并将自己设置为合作者?

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

13 回答

  • 102

    私有克隆URL的格式为 git@github.com:username/repo.git - 也许您需要使用 git@ 而不是 git://

    git:// URL是只读的,看起来私有存储库不允许这种形式的访问 .

  • 5

    这对我有用:

    git clone https://username@github.com/username/repo_name

    当然,这是在adding my SSH key to Github之后 . 我在CentOs服务器上使用它,如果有必要的话 .

  • 0

    这对我有用:

    git clone https://username:password@github.com/username/repo_name.git
    
  • 3

    使用Git for Windows可以更轻松地使用HTTPS网址 .

    打开一个git shell然后 git clone https://github.com/user/repo . 出现提示时输入用户名和密码 . 无需设置SSH密钥 .

  • 125

    看在上帝的份上,我已经多次遇到过这个问题,每次登陆这个页面,都会尝试一切并失败!

    It's because I have 2FA enabled!!!

    根据https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled

    如果您启用了双因素身份验证,或者您正在访问使用SAML单点登录的组织,则必须提供个人访问令牌,而不是输入HTTPS Git的密码 .

    • 关注this link并创建访问令牌

    • git clone https://github.com/username/repo_name.git (默认的git repo链接已经足够了!)

    • 输入您的用户名并使用访问令牌作为密码!!


    更新:

    如果您不介意在命令行中公开访问令牌,您还可以将访问令牌粘贴为用户名,然后按Enter键输入(不需要密码) .

  • 0

    为了回应mac的回答,您可以在github repo页面上获取SSH克隆URL,方法是单击 You can clone with HTTPS, SSH, or Subversion. 上的 SSH 并复制URL .

  • 11

    除了MK Yung的回答:如果您不想收到403 Forbidden响应,请确保在部署到repo的部署密钥的任何地方添加公钥 .

  • 0

    首先确保您拥有SSH密钥或生成一个:https://help.github.com/articles/generating-ssh-keys/

    获得密钥后,您必须将其添加到您的github帐户:https://github.com/settings/ssh

    对于Windows用户,以管理员身份运行git bash很有用 .

    现在克隆应该适用于私有存储库(repo),而不必输入您的用户名和密码 .

  • 3

    对我来说,解决方案是:

    git clone https://myusername@restoftherepolink.git
    

    这里有一件与@charlchad答案不同的是

    git clone https://username@github.com/username/repo_name
    

    在这里你需要成为回购的所有者,但如果你不是,那么它将成为

    git clone https://myusername@github.com/ownersusername/repo_name.git
    
  • 3

    这对我来说很有用_我是 git clone https://username@github.com:username/repo_name

  • 16

    在github中添加桌面ssh公钥 .

    https://github.com/settings/keys

    您可以在没有任何密码的情况下克隆存储库 .

  • 26

    If the newly used computer has different credentials 正在运行此命令

    git clone https://github.com/username/reponame.git

    直接不行 . Git将尝试使用存储的凭据,不会提示您输入用户名和密码 . 由于凭据不匹配,git将输出 Repository not found 并且克隆操作失败 . 我解决它的方法是删除旧凭据,因为我不再使用它们,并再次运行上面提到的命令并输入所需的用户名和密码并克隆私人仓库 .

  • 2

    我有一个公司(私人)帐户和2因素身份验证启用,所以我必须结合几个帖子,使其工作如下 . (记下来因此对于具有相同情况的人可能有用)

    Initially it was the Fatal Error. 
    fatal: repository 'https:
    ...
    remote: Repository not found.
    fatal: repository 'https:
    

    安装了凭证管理器和更新的GIT,如下所述:https://codeshare.co.uk/blog/how-to-solve-the-github-error-fatal-httprequestexception-encountered/

    这并没有解决问题,因为当我尝试使用clone命令时问题转移到下面,如下所示:

    $ git clone https://<username>:<password>@github.com/<ORG_NAME>/<PROJECT-NAME>.git
    
    remote: Invalid username or password.
    fatal: Authentication failed for 'https://
    

    My password had $ symbol in it 由于某种原因,GIT命令行/ GIT Bash不喜欢它 . 我可以看到这个错误返回文本没有$符号 .

    fatal: Authentication failed for 'https://<username>:<password-missing-$-symbol>@github.com/<ORG_NAME>/<PROJECT-NAME>.git'
    

    我不得不引用这个网站:https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

    请注意:如果在Windows Credential Manager中为您的帐户存储了错误的密码,它也会增加问题 . 在移至下面的步骤之前,我删除了以这种方式存储的github凭据 .

    $ git config --global credential.helper cache
    $ git clone https://<username>:<password>@github.com/<ORG_NAME>/<PROJECT-NAME>.git
    

    现在弹出Windows凭据管理器 . 我在文本框中键入了我的用户名和密码(这接受了我的密码有$符号)并提示我输入双因素身份验证代码 . 我从Google身份验证器输入了身份验证代码,克隆启动完美 .

相关问题