Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

两种方法解决git每次push都要填写账号密码问题 #28

Open
deepthan opened this issue Feb 27, 2018 · 0 comments
Open

两种方法解决git每次push都要填写账号密码问题 #28

deepthan opened this issue Feb 27, 2018 · 0 comments

Comments

@deepthan
Copy link
Owner

Github获取远程库时,有ssh和https方式,前者可以直接连接无需输入账号密码而后者需要:

  • ssh方式关联
  1. 在git clone的时候使用ssh方式
  2. 修改连接远程仓库的url
// 移除旧的关联
$ git remote rm origin  
// 添加新的关联
$ git remote add origin git@github.com:deepthan/Front-end-resource-collection.git  
  • https方式关联
  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 操作的就是上面最后一行的值

参考:解决向github提交代码是老要输入用户名密码

@deepthan deepthan changed the title 使用ssh和https两种方法解决git每次push都要填写账号密码问题 两种方法解决git每次push都要填写账号密码问题 Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant