如何在Git中更改用户名?

3
我知道这是一个常见的问题,但即使我采用了各种解决方案,我仍然无法更改用户名。每次尝试将我的更改推送到git时,我都会收到以下错误信息。 PS C:\storage\class\11-1\Angular> git push origin DevBW-AngularAws remote: Permission to varun9797/BetterWorldUI.git denied to test9777. fatal: unable to access 'https://github.com/varun9777/BetterWorldUI.git/': The requested URL returned error: 403 我也尝试了以下命令。 git config credential.username "varun9777" 但仍然在推送时遇到相同的错误。
我想把用户名从abc-xyz改为varun9777 请帮忙,谢谢。

前往 Github 存储库页面获取新的 URL。然后使用 git remote set-url origin https://new url with username replaced 命令将 URL 更新为您的新用户名。 - Sourav Dutta
请在您的情况下执行以下操作:git remote set-url origin https://github.com/varun9797/BetterWorldUI.git/ - Sourav Dutta
仍然得到相同的错误。 - Varun verma
6个回答

2
git remote set-url origin https://varun9797:yourPassword@github.com/varun9797/BetterWorldUI.git

我们可以设置包含git凭证的存储库url。最初的回答。

在这里,github密码将以明文形式存储在您的.git目录中,这显然是不可取的。 - Nile
没问题,我认为git config user.password ...也会将git密码存储在.git目录中。 - Wang Liang

1

尝试按顺序执行这些操作

git remote set-url origin https://varun9797:yourPassword@github.com/varun9797/BetterWorldUI.git
git config --global user.email "verma9797@gmail.com"
git config --global user.name "varun verma"
git config --global credential.username "varun9797"

进入你的.git文件夹,然后打开config文件。在文件中粘贴你的用户信息:

[remote "origin"]
    url = https://github.com/varun9797/BetterWorldUI.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = varun-verma
    email = verma9797@gmail.com

根据您的建议,我尝试了。但仍然出现相同的错误。<br> PS C:\ storage \ class \ 11-1 \ Angular> git config user.email“verma9797@gmail.com” <br> C:\ storage \ class \ 11-1 \ Angular> git config user.name“varun verma”<br> C:\ storage \ class \ 11-1 \ Angular> git config credential.username“varun9797” <br> C:\ storage \ class \ 11-1 \ Angular> git push origin DevBW-AngularAws 远程:拒绝将varun9797 / BetterWorldUI.git权限授予shivam-perpetualny。 致命错误:无法访问'https://github.com/varun9797/BetterWorldUI.git/':请求的URL返回错误:403 - Varun verma

0

你可以尝试检查版本。他们说版本1.7.10更稳定、更舒适。检查一下是否在推送到旧版本。第二个建议是,可以使用SSH而不是HTTPS URL。链接-https://help.github.com/articles/changing-a-remote-s-url。 - Varchaleswari Ganugapati

0

问题在于不存在一个特定的用户名,而是存在许多个用户名。

您可以在Git配置中设置user.name。这将设置放入您所做的新提交中的名称。通常它没有其他功能,但是任何程序都可以随时查询它并根据需要使用它(无论它是什么程序)。

有些URL中嵌入了用户名:

git push ssh://joe@example.com/path/to/repo.git

将用户名joe嵌入SSH URL中,并:

git fetch https://user:password@host.example.com/path/to/repo.git

嵌入了用户名称user和他的密码(通常不明智)。

您提出的credential.username似乎没有被任何东西使用,尽管由于任何人随时可以编写任何程序并为任何目的使用任何字符串,因此可能有人这样做了,但是对于credential.username的Google搜索主要是像https://sysadminguides.org/2017/05/02/how-to-pass-credentials-in-powershell/这样与Git无关的页面。

Pro Git书籍建议在Windows上,您可能希望安装Git Credential Manager for Windows。

无论如何,一旦您安装了某些凭据助手或选择使用Git本身内置的凭据助手之一,您可以通过git config --global credential.helper helper选择要使用的哪个凭据助手。从您的问题中并不清楚您现在正在使用哪个凭据助手;但是无论您使用哪个,那个决定了您需要更改的设置。

0

尝试在远程连接字符串中设置您的用户名:

$ git remote -v
https://github.com/varun9797/BetterWorldUI.git/

$ git remote remove origin

$ git remote add origin https://username@github.com/varun9797/BetterWorldUI.git/

现在当您尝试推送/拉取时,它应提示您输入密码。


0

试试这个:

git remote set-url origin https://username@github.com/user/BetterWorldUI.git 

其中username应该是varun9797


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接