Git push 需要用户名和密码 [英] Git push requires username and password

查看:74
本文介绍了Git push 需要用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的 GitHub 帐户克隆了一个 Git 存储库到我的 PC.

I cloned a Git repository from my GitHub account to my PC.

我想同时使用 PC 和笔记本电脑,但需要一个 GitHub 帐户.

I want to work with both my PC and laptop, but with one GitHub account.

当我尝试使用我的电脑向 GitHub 推送或从 GitHub 拉取数据时,它需要用户名和密码,但在我使用笔记本电脑时不需要!

When I try to push to or pull from GitHub using my PC, it requires a username and password, but not when I'm using the laptop!

我不想每次与 origin 互动时都输入我的用户名和密码.我在这里遗漏了什么?

I don't want to type my username and password every time I interact with origin. What am I missing here?

推荐答案

一个常见的原因是使用默认 (HTTPS) 而不是 SSH 进行克隆.您可以通过转到您的存储库,单击克隆或下载",然后单击使用 SSH"来更正此问题.URL 字段上方的按钮并更新源远程的 URL,如下所示:

A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:

git remote set-url origin git@github.com:username/repo.git

您可以使用以下方法检查是否已将远程添加为 HTTPS 或 SSH:

You can check if you have added the remote as HTTPS or SSH using:

git remote -v

这在 GitHub 上有记录:将远程 URL 从 HTTPS 切换到 SSH.

This is documented at GitHub: Switching remote URLs from HTTPS to SSH.

这篇关于Git push 需要用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆