[转]解决git指令更新远程仓库github时每次都要输入用户名和密码问题

转自https://blog.csdn.net/qq_15809599/article/details/61239292

使用命令

在git bash 中执行 
设置记住密码(默认15分钟): 
git config –global credential.helper cache 
如果想自己设置时间,可以这样做: 
git config credential.helper ‘cache –timeout=3600’ 
这样就设置一个小时之后失效 
长期存储密码: 
git config –global credential.helper store

使用ssh方式(推荐)

1、在每次push 的时候,都要输入用户名和密码,是不是很麻烦?原因是使用了https方式 push,在git bash里边输入 git remote -v

$ git remote rm origin    //删除http
$ git remote add origin git@github.com:sosout/myblog.git   //添加shh
$ git push origin   //执行你的更改
  • 1
  • 2
  • 3

再次执行 git remote -v 查看是否更新成功(对比第一次执行)

ssh-keygen -t rsa -C “email”   
添加你的SSH公钥(email是你github注册账号的邮箱)
  • 1
  • 2
  • 第一次出现:Enter file in which to save the key (/root/.ssh/id_rsa): 直接按回车就行

  • 第二次出现:Enter passphrase (empty for no passphrase): 第一次输入公钥密码(推荐不用输入,直接回车,以便在clone、pull、push等不用输入公钥密码)

  • 第三次出现:Enter same passphrase again: 再次输入公钥密码

公钥创建成功,位置在你使用 git bush 的当前项目目录下(xx.pub)

公钥和私钥配对,接下来去C盘找你的私钥

私钥一般在你的用户文件夹的 .ssh下,打开xx.pub,复制内容,在github中创建ssh keys (没有私钥,百度)

接下来 push 就不需要密码了

如果你遇到以下问题,请仔细查看自己的公钥和私钥有没有分清
Permission denied (publickey).
fatal: The remote end hung up unexpectedly.

Permission denied (publickey).
fatal: Could not read from remote repository.
  • 1
  • 2
  • 3
  • 4
  • 5

ssh机制,简单的说,要使本地主机和远程服务器通过ssh连接,需要一对密钥,一个是私钥,存在于本地主 
机,另一个是公钥,放在远程服务器。

初学者常用指令(如果需要高端的,自己去百度,一大堆)

  • 同步github的项目到本地(前提是你的github上已有仓库,怎么在github上创建仓库new repository)
git clone git@github.com:512439130/512439130.github.io.git (http,在你的download下复制) 

git clone https://github.com/512439130/512439130.github.io.git  (ssh,同理)

//将工作文件修改提交到本地暂存区
git add <文件名.后缀>
git add .  //当前仓库下所有更新的文件

//删除本地,并将任务提交到缓存区
git rm <文件名.后缀>

//查看项目状态(未提交)
git status  

//准备提交
git commit -m "更新记录(此处随便写,就是记录你更新的日志)"

//正式提交
git push 

//查看更新日志
git log

//更新远程仓库到本地
git pull
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值