zoukankan      html  css  js  c++  java
  • git 记住用户名和密码

    git 记住用户名和密码

    在使用 git 时,如果用的是 HTTPS 的方式,则每次提交,都会让输入用户名和密码,久而久之,就会感觉非常麻烦,那么该如何解决呢?

    1. 使用 SSH,添加 ssh key。

    2. 在全局中存储用户的账号密码,方式如下

    第一步:在 %HOME% 目录中,创建 .git-credentials 文件

    一般为 C:usersAdministrator,也可以是你自己创建的系统用户名目录,反正都在 C:users*** 中。

    Windows 中创建以 . 开头的文件的方法:

    1. 新建 test.txt 记事本,然后另存为 .git-credentials

    2. 使用 git bash

       touch .git-credentials
      

    创建完成后,在该文件中输入:

    https://username:password@github.com
    

    注:username 对应你的用户名,password 对应你的密码

    第二步:再进入 git bash 中

    git config --global credential.helper store
    

    store 为永久存储,当然也可以设置临时的

    # 临时存储,默认为15分钟
    git config –global credential.helper cache
    # 设置保存时间
    git config credential.helper 'cache –timeout=3600'
    

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

    [credential]helper=store
    

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

    3. 单独对某个项目免密

    如果还未添加远程地址,可以输入一下命令:

    git remote add origin https://username:password@git.oschina.net/diligentyang/ysy107lab.git 
    

    如果已添加远程地址,最为简单的方式就是,直接在 .git/config 文件中进行修改,按如上格式,添加用户名和密码

    git config --list
    git config --global user.name "输入你的用户名"
    git config --global user.email "binarylei@qq.com"


    每天用心记录一点点。内容也许不重要,但习惯很重要!

  • 相关阅读:
    设计模式学习笔记--迭代器模式
    设计模式学习笔记--组合模式
    设计模式学习笔记--备忘录模式
    Asp.Net Core IdentityServer4 中的基本概念
    Asp.Net Core 中间件应用实践中你不知道的那些事
    Asp.Net Core Filter 深入浅出的那些事-AOP
    ASP.NET CORE 内置的IOC解读及使用
    ASP.NET CORE 管道模型及中间件使用解读
    ASP.NET CORE 启动过程及源码解读
    Linux +Docker +Nginx 部署代理转发初探
  • 原文地址:https://www.cnblogs.com/binarylei/p/8680754.html
Copyright © 2011-2022 走看看