解决向github提交代码每次都要求输入密码的问题(转)

 方法一:

  (其实就只需要一句话:git config --global credential.helper store)

  1. 在命令行输入命令:
    git config --global credential.helper store
    ☞ 这一步会在用户目录下的.gitconfig文件最后添加:
    [credential]
        helper = store
  1. 现在push你的代码 (git push), 这时会让你输入用户名密码, 这一步输入的用户名密码会被记住, 下次再push代码时就不用输入用户名密码啦!
    ☞这一步会在用户目录下生成文件.git-credential记录用户名密码的信息.
    git config --global 命令实际上在操作用户目录下的.gitconfig文件, 我们cat一下此文件(cat .gitconfig), 其内容如下:
[user]
    name = alice
    email = alice@aol.com
[push]
    default = simple
[credential]
    helper = store

git config --global user.email "alice@aol.com" 操作的就是上面的email
git config --global push.default matching 操作的就是上面的push段中的default字段
git config --global credential.helper store 操作的就是上面最后一行的值



作者:元亨利贞o
链接:https://www.jianshu.com/p/81ae6e77ff47
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
方法二:

修改代码根目录的隐藏配置文件 " .git/config "文件

[remote "origin"]
url = https://username:passwd@github.com/dotheright/mylovelycodes.git
fetch = +refs/heads/*:refs/remotes/origin/*

 

username 改为你的用户名

passwd 改为你的密码

中间的冒号不能省略

原理上讲其实就是URL的格式,里面可以带用户名密码.

 
posted @ 2018-01-18 16:46  jaysonguo  阅读(402)  评论(0编辑  收藏  举报