Git踩坑指南

最近入职了七牛云,因为安全性的原因,加入github上的开发小组必须开启二次验证,今天想上传一个新的demo代码,搞了半天老是说我账号密码不对,RSA也不行,经过多次重试并且之前也使用git,所以我确定我的操作没有错,问题就在账号的二次验证上,经过一番曲折,终于搞定了,所以决定写下一篇博客作为记录,也为了他人遇到此问题快速查找解决方式,避免浪费时间。此博客会不断更新,作为一个git错误解决方式的集锦。

一、github开启二次验证之后使用git无法push

当你开启github二次密码验证后,你就会发现你push的时候要你的账号密码,而你怎么输都输不对

shaolongfeis-MacBook-Pro:MyOpenGLDemo shaolongfei$ git push origin master
Username for 'https://github.com': s15603333319
Password for 'https://s15603333319@github.com': 
remote: Invalid username or password.

这就很让人抓狂,你反复的输入密码,修改密码,还是不对。因为你开启了二次验证,你这里就不能用密码登录了而是要用Personal access token作为密码登录,这个token在哪获取呢?

1.在网页上登录github

2.你的头像 -> Settings -> Developer settings -> Personal access tokens -> Generate new token

然后填写token的描述啊 权限范围什么的 最后生成token

这个token你最好记下来,以后就查看不了了,可以更新和删除重建,现在你就可以拿着这个token去在push的时候登录了,登陆一次后git会自己记下来,以后就不用你自己输了。

二、github二次验证如何设置短信验证

如果你相要在github的二次验证中设置短信验证,你会发现一个问题,它不提供中国手机号的验证,怎么办呢?这能难倒咱们这些搞技术的吗?

道理很简单啊,直接改下网页就好了

把它传值改掉就可以,页面显示其实没必要动

这样你就可以收到短信啦

三、git push出现错误: Updates were rejected because the remote contains work that you do

To https://github.com/s15603333319/AndroidOpenGL.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/s15603333319/AndroidOpenGL.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这个问题出现的原因是本地仓库与线上仓库的内容不匹配,或者说本地相对于远程不是最新,可以先pull更新本地,再把自己的push上去。如果你确定没问题可以git push -f强行上传。

git pull origin master

四、git pull出现错误:refusing to merge unrelated histories

warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/s15603333319/AndroidOpenGL
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

这个错误产生的原因是合并了两个不同的开始提交的仓库,git 觉得这两个仓库可能不是同一个,所以就报错。

如果你确认没提交错origin 可以使用git pull origin master --allow-unrelated-histories来告诉 git 允许不相关历史合并

五、git push 出现错误error: failed to push some refs to xxx

出现错误的主要原因是github中的README.md文件不在本地代码目录中

git pull --rebase origin master

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幽蓝丶流月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值