• linux下解决 git clone每次都要输入用户名密码问题(推荐)


    一、背景:

    git clone代码或者push代码时候需要输入账号密码

    二、解决方法:

    1、ssh方式:

    先用git config --global user.name 'username’和git config --global user.email 'xxx@xxx.com’配置一下用户名和邮箱
    生成ssh公钥:ssh-keygen -t rsa -C “xxxxx@xxxxx.com”,查看~/.ssh/id_rsa.pub文件内容,获取到你的public key,粘贴到GitLabssh公钥管理处即可
    使用git clone http://git.gitxxx.com/xxx.git,先测试一下,看能不能拉取成功。如果成功,向下进行。此时还是会询问用户名和密码的。

    2、免密拉取配置

    (1)cd到~/目录下,创建一个文件:touch .git-credentials
    vim .git-credentials
    (2)然后输入https://{username}:{password}@git.gitxx.com,比如http://fengjiaheng:password@git.gitxx.com
    (3)然后执行:git config --global credential.helper store
    (4)然后使用git config --list或者查看一下~/.gitconfig文件,会发现多了一行[credential] helper = store
    (5)这时候再用 git 拉取仓库就不需要输入用户名和密码了。
    注意:第4步必须要做,否则做完4、5步之后也不能免密码拉取成功,需要再次执行第4步骤。

    3、粗暴使用型

    Git Clone命令直接使用用户名密码Clone

    git clone http://userName:password@链接
    修改为 git clone https://username:password@链接

    示例:
    git clone git@http://112.12.122.22:t-mapi/hotel-tapi.git
    修改为
    git clone ‘http://username:password@112.12.122.22:t-mapi/hotel-tapi.git’

    注意:

    (1)http -> https
    (2)如果账号username或者password中有@符号,需要 将@替换为%40
    (3)如果报错git clone event not found,需要将 git clone 后地址加上引号 ‘’

    三、总结:

    1、第二种方法比较简单(推荐使用),但是第一二种方法中都首次都必须自己输入账号密码
    2、第三种一次都不用输入账号密码(推荐使用)

  • 相关阅读:
    【LeetCode】57. 插入区间
    资源道具化
    【汇编】#5 80x86指令系统其一(数据传送与算术)
    前端笔记01---html 的加载
    Java - ReentrantLock锁分析
    JavaScrip学习
    软考中级(软件设计师)——程序设计语言与语言处理程序基础(3-5分,一般是3分)
    volatile 关键字有什么用?它的实现原理是什么?
    离线语音模块初步学习——LSYT201B(深圳雷龙发展)
    计算机毕业设计(附源码)python支持智能化管理的仓库管理
  • 原文地址:https://blog.csdn.net/jh035512/article/details/127980837