Sol*_*mon 198 git private github
我在Github上有一个私人存储库用于我正在进行的项目.到目前为止,我只在我的家用台式机上工作,但我刚买了一台笔记本电脑,并且我正在设置它,以便我可以从任何一台计算机上工作,并推/拉更改.
我为笔记本电脑的Github帐户添加了一个新的SSH密钥,并成功克隆并更改了我设置的公共测试仓库.但是,我无法克隆私人仓库.在命令行中我需要做些什么特别的事情才能克隆私人仓库?我是否需要为笔记本电脑设置一个新的GitHub帐户并将自己设置为合作者?
我用的命令是 git clone git://github.com/myusername/reponame.git
小智 374
You can clone a private repository from your account and you can also clone a private repository from organization if you're its owner or member.
*pat is PAT(Personal Access Token).
git clone https://<pat>@github.com/<your account or organization>/<repo>.git
Run Code Online (Sandbox Code Playgroud)
To clone a private repository from your account or organization, you need to generate a PAT(Personal Access Token) on your Github account, and add it to the command above. *Organization doesn't have PAT generator.
1、进入“设置”:
2、向下滚动然后转到“开发者设置”:
3、按“个人访问令牌”,然后按“生成新令牌”:
4、填写“Note”,然后勾选“repo”:
*如果未选中“repo” ,则无法克隆私有存储库。
5,向下滚动然后按“生成令牌”:
6、最后生成PAT :
这是带有上面生成的 PAT 的命令:
git clone https://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@github.com/<your account or organization>/<repo>.git
Run Code Online (Sandbox Code Playgroud)
小智 152
私有克隆URL采用的形式git@github.com:username/repo.git- 也许您需要使用git@而不是git://?
git:// URL是只读的,看起来私有存储库不允许这种形式的访问.
cha*_*had 132
这对我有用:
git clone https://username@github.com/username/repo_name
当然,这是在将我的SSH密钥添加到Github之后.我在CentOs服务器上使用它,如果有必要的话.
izi*_*k f 56
这对我有用:
git clone https://username:password@github.com/username/repo_name.git
Run Code Online (Sandbox Code Playgroud)
med*_*zid 49
使用个人访问令牌是可行的,但是您可能更愿意将令牌访问范围缩小到仅您想要克隆的存储库
Github 推出细粒度个人访问令牌,它可以做到这一点。
以下是要遵循的步骤:
最后点击“生成令牌”按钮
获得令牌后,复制它并运行命令
git clone https://oauth2:<YOUR-TOKEN-HERE>@github.com/<your_user>/<your_repo>.git
Run Code Online (Sandbox Code Playgroud)
就是这样。
lzl*_*31x 46
看在上帝的份上,我已经多次遇到过这个问题,每次登陆这个页面,都会尝试一切并失败!
这是因为我启用了2FA!
根据https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled
如果您启用 了双因素身份验证,或者您正在访问使用SAML单点登录的组织,则 必须 提供个人访问令牌, 而不是输入HTTPS Git的密码.
git clone https://github.com/username/repo_name.git (默认的git repo链接足够好!)更新:
如果您不介意在命令行中公开访问令牌,您还可以将访问令牌粘贴为用户名,然后按Enter键输入(不需要密码).
Luh*_*uhn 34
settings > developer settings > personal access token链接: https: //github.com/settings/tokensgenerate new token这将生成一个看起来像这样的令牌:
现在使用以下命令:
git clone https://user:TOKEN@github.com/username/repo.git
Run Code Online (Sandbox Code Playgroud)
已过时:尝试以下命令:
git clone https://user:pass@github.com:username/repo.git
Run Code Online (Sandbox Code Playgroud)
将解决以下错误:
Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
并将您链接到以下支持页面:
单击您的图标配置文件并转到(使用上面的链接获取更多指导):
settings> developer settings> personal acces token > generate new token
小智 18
使用Git for Windows可以更轻松地使用HTTPS网址.
然后打开一个git shell git clone https://github.com/user/repo.出现提示时输入用户名和密码.无需设置SSH密钥.
Bla*_*mba 14
对我来说,解决方案是:
git clone https://myusername@restoftherepolink.git
Run Code Online (Sandbox Code Playgroud)
在这里,您需要成为存储库的所有者,但如果不是,则它将作为
git clone https://myusername@github.com/ownersusername/repo_name.git
Run Code Online (Sandbox Code Playgroud)
如果有的2FA enabled话:
git clone https://myusername@restoftherepolink.gitAma*_*Neo 12
每个人都知道克隆的过程,我想在这里添加更多的东西。不要担心特殊字符或将“@”写成“%40”,请参阅字符编码
$ git clone https://username:password@github.com/user/repo
Run Code Online (Sandbox Code Playgroud)
这条线可以胜任
为了解决这个问题,我鼓励使用 GitHub 开发人员选项来生成访问令牌。我相信访问令牌是安全的,您不会找到任何特殊字符。
现在我将编写以下代码来访问我的存储库。
$ git clone https://username:token@github.com/user/repo
Run Code Online (Sandbox Code Playgroud)
我只是用 Access-token 替换我的原始密码,现在我不担心是否有人看到我的访问凭证,我可以随时重新生成令牌。
Rtm*_*tmY 11
从这里:
2020 年 7 月,我们宣布打算要求所有经过身份验证的 Git 操作使用基于令牌的身份验证(例如个人访问、OAuth 或 GitHub 应用程序安装令牌)。从 2021 年 8 月 13 日开始,我们在 GitHub.com 上验证 Git 操作时将不再接受帐户密码。
今天你需要做什么
对于开发人员来说,如果您今天使用密码来验证 GitHub.com 上的 Git 操作,则必须在 2021 年 8 月 13 日之前开始通过 HTTPS(推荐)或 SSH 密钥使用个人访问令牌,以避免中断。如果您收到警告,指出您正在使用过时的第三方集成,则应将客户端更新到最新版本。
对于集成商,您必须在 2021 年 8 月 13 日之前使用 Web 或设备授权流程对集成进行身份验证,以避免中断。有关更多信息,请参阅授权 OAuth 应用程序和开发者博客上的公告。
在命令行上使用令牌
1)创建个人访问令牌 - follow此操作。
2 ) 获得令牌后,您可以在通过 HTTPS 执行 Git 操作时输入令牌而不是密码。
例如,在命令行上您可以输入以下内容:
$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token # <----- Bingo!
Run Code Online (Sandbox Code Playgroud)
(*)在此查看更多内容。
我需要一种非交互式方法来克隆私有存储库。
受此问题启发:https : //github.com/github/hub/issues/1644
第1步。
在 github 开发者设置中创建个人访问令牌:https : //github.com/settings/tokens
第2步。
git clone https://$token:x-oauth-basic@github.com/$username/$repo.git
Run Code Online (Sandbox Code Playgroud)
我有一个公司(私人)帐户并启用了2-Factor-Authentication,所以我不得不合并一些帖子才能使其正常工作,如下所示。(记下来,这样对情况相同的人可能有用)
Initially it was the Fatal Error.
fatal: repository 'https:
...
remote: Repository not found.
fatal: repository 'https:
Run Code Online (Sandbox Code Playgroud)
如此处所述安装凭证管理器并更新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://
Run Code Online (Sandbox Code Playgroud)
我的密码中带有$符号,由于某种原因,GIT命令行/ GIT Bash不喜欢它。在错误返回的文本中没有$符号的情况下,我可以看到它。
fatal: Authentication failed for 'https://<username>:<password-missing-$-symbol>@github.com/<ORG_NAME>/<PROJECT-NAME>.git'
Run Code Online (Sandbox Code Playgroud)
我不得不引用此站点: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
Run Code Online (Sandbox Code Playgroud)
现在,Windows凭据管理器弹出。我在文本框中输入了用户名和密码(这接受了带有$符号的密码),并提示我输入2-Factor身份验证代码。我输入了Google Authenticator的身份验证代码,克隆成功启动。
小智 6
从启用 2FA 的私有存储库克隆时,您需要遵循一个简单的步骤
当您收到 Private repo 的 Authentication failed 错误消息时,请按照相同的步骤操作
为了响应Mac的答案,你可以得到你的SSH克隆网址您的GitHub库页上,单击SSH上You can clone with HTTPS, SSH, or Subversion.,然后复制URL.