使用 Git Bash 配置用户和密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8840551/
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 12:43:46  来源:igfitidea点击:

Configuring user and password with Git Bash

gitgithubcredentials

提问by eeejay

I am using Git Bash on Windows 7. We are using GitHub as our repository origin.

我在 Windows 7 上使用 Git Bash。我们使用 GitHub 作为我们的存储库来源。

Every time I push or pull I have to provide user and password credentials. I know that my SSH keys are set up correctly, otherwise I would not be able to access the repository. (That is, once I enter my credentials the push/pull works correctly.)

每次推送或拉取时,我都必须提供用户和密码凭据。我知道我的 SSH 密钥设置正确,否则我将无法访问存储库。(也就是说,一旦我输入了我的凭据,推/拉就可以正常工作。)

I have entered

我已经进入

git config --global user.name myusername
git config --global user.email myemail
git config --global github.user myusername
git config --global github.token mytoken

But nonetheless I am being asked for credentials each and every time I push/pull.

但尽管如此,每次我推/拉时,我都会被要求提供凭据。

采纳答案by manojlds

Make sure you are using the SSH URL for the GitHub repository rather than the HTTPS URL. It will ask for username and password when you are using HTTPS and not SSH. You can check the file .git/configor run git config -eor git remote show originto verify the URL and change it if needed.

确保您使用 GitHub 存储库的 SSH URL 而不是 HTTPS URL。当您使用 HTTPS 而不是 SSH 时,它会要求输入用户名和密码。您可以检查文件.git/config或运行git config -egit remote show origin验证 URL 并在需要时更改它。

回答by IcedDante

From Git Bash I prefer to run the command:

在 Git Bash 中,我更喜欢运行以下命令:

git config --global credential.helper wincred

At that point running a command like git pulland entering your credentials one time should have it stored for future use. Git has a built-in credentials system that works in different OS environments. You can get more details here: 7.14 Git Tools - Credential Storage

在这一点上运行类似的命令git pull并输入您的凭据一次应该将其存储以备将来使用。Git 有一个内置的凭证系统,可以在不同的操作系统环境中工作。您可以在此处获取更多详细信息:7.14 Git 工具 - 凭证存储

回答by u7565209

For those who are using access token and a Windows environment, there is a simple way to do it:

对于那些使用访问令牌和 Windows 环境的人,有一个简单的方法来做到这一点:

Start menu → Credential ManagerWindows Credentials→ find the line (Git: https://whatever/your-repository/url) → edit, user nameis PersonalAccessToken and passwordis your access token.

开始菜单 →凭证管理器Windows 凭证→ 找到该行 (Git: https://whatever/your-repository/url) → 编辑, 用户名是 PersonalAccessToken,密码是您的访问令牌。

回答by primChareka

If you are a Mac user and have keychain enabled, you to need to remove the authorization information that is stored in the keychain:

如果您是 Mac 用户并且启​​用了钥匙串,则需要删除存储在钥匙串中的授权信息:

- Open up Keychain access
- Click "All items" under category in the left-hand column
- Search for git
- Delete all git entries.

Then you should change your username and email from the terminal using git config:

然后您应该使用git config以下命令从终端更改您的用户名和电子邮件:

$ git config --global user.name "Bob"

$ git config --global user.email "[email protected]"

Now if you try to push to the repository you will be asked for a username and password. Enter the login credentials you are trying to switch to. This problem normally pops up if you signed into GitHub on a browser using a different username and password or previously switched accounts on your terminal.

现在,如果您尝试推送到存储库,系统将要求您输入用户名和密码。输入您尝试切换到的登录凭据。如果您使用不同的用户名和密码或之前在终端上切换过的帐户在浏览器上登录 GitHub,通常会出现此问题。

回答by Null

Try ssh-agent for installing the SSH key for use with Git. It should auto login after use of a passphrase.

尝试使用 ssh-agent 安装用于 Git 的 SSH 密钥。它应该在使用密码后自动登录。

回答by notreadbyhumans

With git bash for Windows, the following combination of the other answers worked for me (repository checked out using the GitHub client i.e. https, not ssh):

对于 Windows 的 git bash,其他答案的以下组合对我有用(使用 GitHub 客户端即 https,而不是 ssh 检出存储库):

  1. Generate a Personal Access Token
  2. Start a git bash session within your repo
  3. run git config --global credential.helper wincred
  4. run git pull
  5. give PersonalAccessToken as the username
  6. give the Personal Access Token as the password
  1. 生成个人访问令牌
  2. 在你的 repo 中启动一个 git bash 会话
  3. git config --global credential.helper wincred
  4. git pull
  5. 将 PersonalAccessToken 作为用户名
  6. 将个人访问令牌作为密码

回答by Jorge

add remote as:

添加远程为:

git remote add https://username:[email protected]/repodir/myrepo.git

回答by Srikanth Yeluri

If your repo is of HTTPS repo, git config -e give this command in the git bash. Update the username and password by opening in insert mode, change the password or username give :x and Cntrl+z keys it will save and exit

如果你的 repo 是 HTTPS repo,git config -e 在 git bash 中给出这个命令。通过在插入模式下打开来更新用户名和密码,更改密码或用户名给 :x 和 Cntrl+z 键,它将保存并退出

So, From then while you pull / push the code to the repository it will not ask for password.

因此,从那时起,当您将代码拉/推到存储库时,它不会要求输入密码。