Git&Github

         本菜鸟最近开始玩Github了,呵呵,好像还挺有意思的哦。不知道小鸟们,赶紧google去,还有大家赶紧follow我。开个玩笑,进入正体。

         最近想把自己做的一个小小小小的应用放到github上去,顺便学习下git和玩玩github,我用两台电脑往github上的项目push代码,想模拟social coding的感觉。呵呵,但是出现了这个错误

To git@github.com:archermind/LEDTorch.apk-for-Android.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:archermind/LEDTorch.apk-for-Android.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

错误产生的原因是,因为我在A电脑上向github上的项目push过代码,而又在B电脑上修改了代码并且要push到github上去,这个时候,git为了避免冲突的发生,rejected。

        正确的做法是,在push之前git fetch origin,将github上的新代码拉下来,然后在本地merge,如果没有冲突就可以push了,如果有冲突的话要在本地解决冲突后,再push。具体做法就是。


         本菜鸟最近开始玩Github了,呵呵,好像还挺有意思的哦。不知道小鸟们,赶紧google去,还有大家赶紧follow我。开个玩笑,进入正体。

         最近想把自己做的一个小小小小的应用放到github上去,顺便学习下git和玩玩github,我用两台电脑往github上的项目push代码,想模拟social coding的感觉。呵呵,但是出现了这个错误

To git@github.com:archermind/LEDTorch.apk-for-Android.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:archermind/LEDTorch.apk-for-Android.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

错误产生的原因是,因为我在A电脑上向github上的项目push过代码,而又在B电脑上修改了代码并且要push到github上去,这个时候,git为了避免冲突的发生,rejected。

        正确的做法是,在push之前git fetch origin,将github上的新代码拉下来,然后在本地merge,如果没有冲突就可以push了,如果有冲突的话要在本地解决冲突后,再push。具体做法就是。

git fetch origin

git merge origin/master

git push origin master

       

当然在github上玩git的时候,还有一些个小问题,菜鸟们要注意了。


1git所使用传输的协议通常有三种,HTTPGitSSH。但是要注意的是,(HTTPGit)通常都是只读的,所以虽然二者对大多数人都可用,但执行写操作时还是需要SSH。所以,到github上你可以看到下图:


想要给githubpush代码的话,记得要用SSH。具体的做法能就是

git remote add origin [ssh那一栏的地址] //不知道有没有说错哦? 牛牛们,给点意见呗



2,由于大多数Git 服务器使用SSH公钥来授权,所以位了能够向github上的特定项目贡献代码,必须将能够表示自己的publickey提交给github上相关项目的维护人员。他们所要做的事就是把给位贡献者SSH生成的publickey加入进来。如下图:



现在好像更流行的办法是fork该项目吧?没用过,有机会去体验下。


总之,git是个好东西,github也挺好玩的,以后有什么经验再来分享。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值