我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。

那么我如何在Git中保存我的凭据?


当前回答

对于Windows用户,这种方式将起作用:

注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它

步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机

其他回答

您可以编辑~/.gitconfig文件以存储凭据:

sudo nano ~/.gitconfig

应该已经有了

[user]
        email = your@email.com
        user = gitUSER

您应该在该文件的底部添加以下内容。

[credential]
        helper = store

我推荐这个选项的原因是因为它是全局的,如果在任何时候你需要删除这个选项,你就知道该去哪里更改它。

仅在个人计算机中使用此选项。

然后,当您拉|clone|输入Git密码时,通常,密码将以以下格式保存在~/.Git凭据中

https://gituser:gitpassword@domain.xxx

其中DOMAIN.XXX可以是github.com、bitbucket.org或其他

请参阅文档。

重新启动终端。

您只需修改~/.git凭据

然后添加以下行:

git:https://<user>:<token/password>@gitlab.com

就是这样

您的问题:

我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,而每次都不需要在提示中输入用户名和密码。那么我如何在Git中保存我的凭据?

如果您是github或其他提供商,我建议不要将它们保存在Git中,例如~/.Git凭据,而是将它们视为加密的机密。

将凭据设置为以下格式:

https://your_user_name:your_token@github.com/your_user_name/your_repo_name.git

将其作为加密机密,如secrets.REPOSTORY:

然后,您可以使用它来克隆公共或私有回购及其子模块,以及自动执行推拉操作

# put the credentials in a variable
export REPOSITORY=${{ secrets.REPOSITORY }}

# git clone public or private repos
git clone --recurse-submodules -j8 ${REPOSITORY}

# git pull will do automatic
cd /path/to/the/repo
git pull

# git push to a branch in the repo
git add . && \
  git commit -m "Action from ${GITHUB_SHA}" && \
  git push --force $REPOSITORY master:$BRANCH

对于Windows用户,这种方式将起作用:

注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它

步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机

要将用户名和用户密码保存到github帐户中,只需按顺序运行这些命令。

git config --global user.name "userName"
git config --global user.email "usernam@gmail.com"
git config --global user.password "userPassword"
git config --global credential.helper store
git config --list --show-origin

然后使用以下命令生成密钥:

ssh-keygen -t rsa -C "useremail@gmail.com"

注意:复制创建id_rsa文件的文件位置然后转到该文件位置-->打开gitbash或命令提示符-->运行命令-cat id_rsa.pub

将显示SSH密钥,复制此SSH密钥并将其粘贴到gihub/gitlab帐户中