git 用户凭据_如何修复Git总是要求用户提供凭据

git 用户凭据

Have you ever encountered Git asking you for your username and password every time you try to interact with GitHub even after configuring it? Well, this is a very common problem among users who use the HTTPS clone URL for their repository. In this article, I’ll show you how to fix this.

您是否曾经在每次尝试与GitHub进行交互后甚至在配置后仍遇到Git询问您的用户名和密码? 嗯,这是在使用HTTPS克隆URL作为存储库的用户中一个非常普遍的问题。 在本文中,我将向您展示如何解决此问题。

The https:// clone URLs are available on all public and private repositories. These URLs work everywhere, even if you are behind a firewall or proxy.

https://克隆URL在所有公共和私有存储库上都可用。 这些URL随处可见,即使您位于防火墙或代理之后。

When you interact with a remote repository using HTTPS URLs on the command line, you’ll be asked for your GitHub username and password, this sucks right?

当您在命令行上使用HTTPS URL与远程存储库进行交互时,将要求您提供GitHub用户名和密码,这很糟糕吗?

Well using an HTTPS remote URL has some advantages: it’s easier to set up than SSH :), and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub user credentials every time you pull or push a repository :(.

很好地使用HTTPS远程URL有一些优点:它比SSH :)设置更容易,并且通常可以通过严格的防火墙和代理进行工作。 但是,每次您拉动或推送存储库:(时,它也会提示您输入GitHub用户凭证。

您可以通过配置Git为您存储密码来解决此问题。 (You can fix this by configuring Git to store your password for you.)

Here’s how:

这是如何做:

  • Update the URL of origin remote using SSH instead of HTTPS;

    使用SSH(而非HTTPS)更新源远程URL。
git remote set-url origin git@github.com:username/repo.git

or

要么

  • Make Git store the username and password and it will never ask for them.

    让Git存储用户名和密码,它永远不会要求他们。
git config --global credential.helper store
  • Save the username and password for a session (cache it);

    保存会话的用户名和密码(将其缓存);
git config --global credential.helper cache
  • You can also set a timeout for the above setting

    您也可以为上述设置设置超时
git config --global credential.helper 'cache --timeout=600'

Bingo, you just fixed it, Git will never ask for your credentials again.

宾果游戏,您只需解决它,Git就不会再要求您提供凭据了。



结论 (CONCLUSION)

However, due to security reasons, it is advisable that you use SSH to interact with GitHub, especially if you work for a company or you’re using a computer that isn’t yours.

但是,出于安全原因,建议您使用SSH与GitHub进行交互,尤其是在为公司工作或使用非您的计算机的情况下。

Using the SSH protocol, you can connect to GitHub without supplying your username or password every time.

使用SSH协议,您无需每次都提供用户名或密码即可连接到GitHub。

Learn how to connect to GitHub with SSH here.

在此处了解如何使用SSH连接到GitHub。

翻译自: https://www.freecodecamp.org/news/how-to-fix-git-always-asking-for-user-credentials/

git 用户凭据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值