git 更改了 GitHub 密码,不再能够推回远程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21745213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:44:08  来源:igfitidea点击:

Changed GitHub password, no longer able to push back to the remote

gitgithub

提问by kenu.heo

After I changed my GitHub password, I am unable to push to the remote:

更改 GitHub 密码后,无法推送到远程:

$ git push origin master
remote: Invalid username or password.

Is there only re clone the repository?

只有重新克隆存储库吗?

回答by Amit

If you had your remote's password changed only, not the username, then try the following command to check remote's info:-

如果您只更改了遥控器的密码,而不是用户名,请尝试以下命令来检查遥控器的信息:-

git remote show origin

git远程显示原点

This will ask for your password for the given git user, fill that in correctly, and now try:-

这将要求您输入给定 git 用户的密码,正确填写,然后尝试:-

git pull

or,

或者,

git push

It should work unless you have to change other things like username or remote URL, you can take a look at the following Git documentation:-

除非您必须更改用户名或远程 URL 等其他内容,否则它应该可以工作,您可以查看以下 Git 文档:-

https://help.github.com/articles/setting-your-username-in-git/

https://help.github.com/articles/changing-a-remote-s-url/

https://help.github.com/articles/setting-your-username-in-git/

https://help.github.com/articles/changed-a-remote-s-url/

回答by hiddenpearls

To update the password in your Terminal. Try the below command, It will prompt you password again.

更新终端中的密码。试试下面的命令,它会再次提示你输入密码。

git push -u origin master

回答by VonC

The OP kenu.heohas worked around the issue by removing, then re-cloning the repo.

OP kenu.heo已经通过去除围绕这一问题的工作,然后再重新克隆回购。

But for other:

但对于其他:

It depends on your OS, git version and protocol you are using.

这取决于您使用的操作系统、git 版本和协议。

Depending on the OS, you have ways to cache your credentials(OSX KeyChain on Mac, netrc credential helper on Windows or Linux), and that could explain why your push isn't working after changing your GitHub password.
For a keychain, you would need to reset that password stored in it.

根据操作系统,您有多种方法可以缓存您的凭据Mac 上的 OSX KeyChainWindows 或 Linux 上的 netrc 凭据助手),这可以解释为什么您的推送在更改 GitHub 密码后不起作用。
对于钥匙串,您需要重置存储在其中的密码

That password issue also suggest that you are using an https url (not an ssh one, which would depends on public/private ssh keys, and wouldn't be influenced by a GitHub account password, since the public SSH key registered to your GitHub account wouldn't have changed).

该密码问题还表明您使用的是 https 网址(不是 ssh 网址,这取决于公共/私人 ssh 密钥,并且不会受到 GitHub 帐户密码的影响,因为公共 SSH 密钥已注册到您的 GitHub 帐户不会变)。

Check that with a git remote -v.

使用git remote -v.

You can force git to use your GitHub login with a:

您可以强制 git 使用您的 GitHub 登录名:

git remote set-url origin https://[email protected]/Username/MyRepo.git

(replace 'Username' and 'MyRepo.git' by your own values)

(用你自己的值替换 ' Username' 和 ' MyRepo.git')

Then try again to push, it should ask for your GitHub password. Enter the new one.

然后再次尝试推送,它应该会询问您的 GitHub 密码。输入新的。

If this doesn't work, check if you have activated the 2FA (2-Form Authentication). If that is the case, you need to generate a PTA (Personal Token Access).
See more at "Configure Git clients, like GitHub for Windows, to not ask for authentication".

如果这不起作用,请检查您是否已激活 2FA(2-Form 身份验证)。如果是这种情况,您需要生成一个 PTA(个人令牌访问)。
请参阅“配置 Git 客户端,例如 Windows 版 GitHub,不要求进行身份验证”。

回答by Sap

On a Windows System none of the steps worked for me, the problem is that the credentials are stored in Windows Credentials Manager.

在 Windows 系统上,所有步骤都不适合我,问题是凭据存储在 Windows 凭据管理器中。

You can go to Control Panel -> User Accounts -> Credential Manager -> Windows Credentials

您可以转到控制面板 -> 用户帐户 -> 凭据管理器 -> Windows 凭据

Under Generic Credentials you will find your git Url, expand the selection and click on edit.

在 Generic Credentials 下,您将找到您的 git Url,展开选择并单击编辑。

Once edited just trigger a git push again and it should work.

编辑后只需再次触发 git push 就可以了。

Source of information :- Remove credentials from Git

信息来源:-从 Git 中删除凭据

回答by Chiron

From what I've experienced, you just need to re-enter the remote-addr.

根据我的经验,您只需要重新输入 remote-addr

And git will ask usr/password for the new one rather than keeping silent and use the deprecated one.

并且 git 会询问 usr/password 以获得新的密码,而不是保持沉默并使用已弃用的密码。

see your remotes, locate which one you want to change

查看您的遥控器,找到您要更改的遥控器

>git remote  
github
gitcafe
company

for example, if you changed your company repo password, you can do:

例如,如果您更改了公司回购密码,您可以执行以下操作:

>git remote remove company

This won't touch your folder, won't touch your commits. This just delete a url-string from git

不会触及您的文件夹也不会触及您的提交。这只是从 git 中删除一个 url-string

Then, add this url again:

然后,再次添加此网址:

>git remote add company https://git.AyCramba.com/xxx.git

Push to it:

推到它:

>git push company master
username for 'https://git.AyCramba.com':
password for 'https://git.AyCramba.com':

Then it starts pushing

然后它开始推

Hope it helps.

希望能帮助到你。

回答by squicc

The username and password may be stored in Windows Credential Manger. Check and update there, if necessary.

用户名和密码可能存储在 Windows 凭据管理器中。如有必要,请检查并更新那里。

(I know that's a bit obvious and simple, but might help some people.)

(我知道这有点明显和简单,但可能对某些人有所帮助。)

回答by Eric Manley

For me, running git on Windows7 using git-bash, running:

对我来说,使用 git-bash 在 Windows7 上运行 git,运行:

git push origin master

Got it working. That prompted Windows7 to ask again for my git creds, and then stored them (whereever Windows does), to update the password.

得到它的工作。这促使 Windows7 再次询问我的 git 凭证,然后存储它们(无论 Windows 在哪里),以更新密码。

回答by ChalkBoard

Ok, the original post is quite old, but it's the top result in Google and none of the answers worked for me. Several other SO and GH posts didn't work either. Posting this to help anyone following me here!

好吧,原来的帖子已经很旧了,但它是谷歌的最佳结果,没有一个答案对我有用。其他几个 SO 和 GH 帖子也不起作用。发布此信息以帮助在这里关注我的任何人!

My situation is slightly different: Personal GH account, pushing to a private Company repo, using SSH and the git command line on Mac. My password is notstored either in my .gitconfignor in any keychain nor in git credential.helper.

我的情况略有不同:个人 GH 帐户,推送到私人公司存储库,在 Mac 上使用 SSH 和 git 命令行。我的密码既没有存储在 my 中,.gitconfig没有存储在任何钥匙串中,也没有存储在 git 中credential.helper

In the example below PersonalName is my GH account, CompanyName is the company (the owner of the repo on GH) and RepoName is the repository.

在下面的示例中,PersonalName 是我的 GH 帐户,CompanyName 是公司(GH 上的存储库的所有者),而 RepoName 是存储库。

My original error message was somewhat different also: attempting git push origin masterresulted in

我原来的错误信息也有些不同:尝试git push origin master导致

remote: Repository not found.
fatal: repository 'https://github.com/CompanyName/RepoName.git/' not found

The remote was working before my GH password change, and I didn't want to remove the remote because I had local changes that I needed to push.

遥控器在我的 GH 密码更改之前正在工作,我不想删除遥控器,因为我需要推送本地更改。

Eventually a reply by seveasto this questionon the GitHub Community Forumpointed me in the right direction. The key thing was to link my GH account name with the remote (private) repo.

最终seveasGitHub 社区论坛上对这个问题的回复为我指明了正确的方向。关键是将我的 GH 帐户名称与远程(私人)存储库相关联。

This worked for me:

这对我有用:

git remote set-url origin https://[email protected]/CompanyName/RepoName.git

Then

然后

git remote show origin

prompted with

提示

Password for 'https://[email protected]': 

I was able to enter my new password, see the remote details and git push origin mastersucceeded.

我能够输入我的新密码,查看远程详细信息并git push origin master成功。