Git一直在尝试访问错误的用户名,当访问远程时。

huangapple go评论76阅读模式
英文:

Git keeps trying to access wrong username when accessing remote

问题

我有一个WSL Ubuntu 20.04系统,我的用户名是firstnamelastname。然而,在我们的git存储库服务器上,我的名字是firstname.lastname。

这似乎让git非常困惑。每次我尝试拉取时,它都试图以firstnamelastname的身份拉取,而不是正确的带有名字之间句点的帐户。

我迄今为止尝试过的方法:

  • 使用-C firstname.lastname重新生成我的SSH密钥,然后将它们复制到服务器上
  • 使用git config --global user.name firstname.lastname设置我的用户名。

这两者都没有起作用。

我该如何解决这个问题?

英文:

I have a WSL Ubuntu 20.04 system where my username is firstnamelastname. On the server for our git repository however, my name is firstname.lastname.

This appears to confuse git a lot. Every time I try to pull, it keeps trying to do so as firstnamelastname, not the correct account with the period between the names.

What I have tried so far:

  • Re-generating my SSH keys with -C firstname.lastname, then ssh-copy-id'ing them to the server
  • Setting my username with git config --global user.name firstname.lastname.

Neither of these have worked.

How do I fix this?

答案1

得分: 2

"-C" 只是向密钥添加注释,不会更改或设置用户名。

由于您正在使用SSH密钥,我假设您正在使用SSH进行git操作。您应该检查存储库的远程位置,因为通常用户名嵌入在远程URL中。

例如,在GitHub上,远程位置看起来像是 git@github.com:my_account/my_repo.git。请注意,用户名在这里设置为git,这是GitHub要求的。您可以设置远程位置以使用任何URL和用户名。

运行 git remote -v 以查看您的远程位置。然后运行 git remote set-url REMOTE_NAME NEW_URL 来更改远程位置和您的用户名。

英文:

The -C just adds a comment to the key, it doesn't change or set a username.

Since you're using an SSH key I'm assuming you're using git over ssh. You should check to see what your remote is for the repository, as the username is normally embedded in the remote URL.

For example, on github the remote would look like git@github.com:my_account/my_repo.git. Note the username is set to git here, which is what github requires. You can set a remote to use any url and username you want.

Run git remote -v to see your remotes. Then run git remote set-url REMOTE_NAME NEW_URL to change the remote and your username.

答案2

得分: -1

尝试配置git并将您的用户名设置为:

git config --global --add --user.name firstname.lastname

您还可以配置您的电子邮件地址以匹配您在git服务器上的电子邮件地址。这样它将关联提交到您的账户。

参考链接:https://git-scm.com/docs/git-config#Documentation/git-config.txt-username

英文:

Try configuring git and set your username as:

git config --global --add --user.name firstname.lastname

You can also configure your email address to match with your email address on your git server. That way it will associate the commits to your account.

Ref: https://git-scm.com/docs/git-config#Documentation/git-config.txt-username

huangapple
  • 本文由 发表于 2023年6月26日 22:25:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定