Git Pull 避免用户名和密码方法

  在开发中使用的版本控制器时git , 每次使用命令"git pull"从服务器获得最新代码时,都需要输入用户名和密码,这样浪费了大量的时间和热情,在此背景下,本文在网上找到解决版本,在此做一个总结,已做留念。

1 查看项目的存放地址

   首先看下每次输入用户名和密码的提示。项目存放在以下地址:

http://192.9.100.193

2 创建 Git 存储用户名和密码

  在%HOME%目录中,一般是 c:/users/{当前用户名} 目录下。文件名为.git-credentials,由于在Window中不允许直接创建以"."开头的文件,所以需要借助git bash进行,打开git bash客户端,进行%HOME%目录,然后用文本编辑器打开文件 .git-credentials,输入以下内容:

touch .git-credentials
vim .git-credentials
http://{用户名}:{密码}@192.9.100.193

3 添加 Git Config内容

  进入git bash终端, 输入如下命令:

git config --global credential.helper store

  执行完后查看%HOME%目录下的.gitconfig文件,会多了一项。

[credential]
    helper = store

  重新开启git bash会发现git push时不用再输入用户名和密码。

  注意:

   如果不能提交代码到git服务器,需要将帐号绑定到git工具上。若不绑定,当你执行git commit  是报如下错误。

    *** Please tell me who you are.  
      
    Run  
      
      git config --global user.email "you@example.com"  
      git config --global user.name "Your Name"  
      
    to set your account's default identity.  
    Omit --global to set the identity only in this repository.  
      

  需要执行 git config --global 命令,全局配置用户的姓名和邮箱,就可以提交git 代码了。

git config  --global user.email {用户邮箱}
git config --global user.name {用户账号}
原文地址:https://www.cnblogs.com/wangshuo1/p/5531200.html