Skip to main content

为什么 Git 总是要求我提供凭据?

如果您在每次尝试与 GitHub 交互时,Git 都会提示输入凭据,很可能是因为您使用了存储库的 HTTPS 克隆 URL。

与使用 SSH 相比,使用 HTTPS 远程 URL 具有一些优势。 它比 SSH 更容易设置,通常通过严格的防火墙和代理进行工作。 但是,每次拉取或推送仓库时,它也会提示你输入 GitHub 凭据。

当 Git 提示你输入密码时,请输入你的personal access token。 或者,可以使用 Git 凭据管理器等凭据帮助程序。 Git 的基于密码的身份验证已被删除,取而代之的是更安全的身份验证方法。 有关详细信息,请参阅“管理个人访问令牌”。

可以通过将 Git 配置为自动缓存凭据,避免提示输入密码。 在配置凭据缓存后,当你使用 HTTPS 拉取或推送存储库时,Git 自动使用缓存的 personal access token。

延伸阅读

  •         [AUTOTITLE](/get-started/git-basics/about-remote-repositories)
    
  •         [AUTOTITLE](/authentication/keeping-your-account-and-data-secure/about-authentication-to-github)
    
  •         [AUTOTITLE](/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)
    
  •         [AUTOTITLE](/get-started/git-basics/caching-your-github-credentials-in-git)