Git本地仓库推到远程仓库

首先创建一个远程仓库,创建完成后添加自己的ssh公钥,公钥生成方法:

$ ssh-keygen -t rsa -C "xxxxx@xxxxx.com"      //按3次回车即可,路径等保持默认

$ cat ~/.ssh/id_rsa.pub     //查看ssh公钥

$ git config –global core.autocrlf false  

初始化仓库前先关闭换行符自动转换,这样在git add时就不会自动转换换行符,而是保留原来的样子,这一步根据自己的需要确定,不是必须的


$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

 

配置自己的名字和邮箱

$ git init        //初始化仓库
$ git remote add origin https://gitee.com/example/example-01.git          //关联到远程仓库
$ git add a.c a.h common.h        //添加将需要的文件

$ git commit -m "The First commit."
$ git push -u origin master        //首次push加-u,之后再push就不用加-u了

 

     


下面是可能出现的错误和解决方法:

错误:

error: src refspec master does not match any. error: failed to push some refs to 'git@github.com:hahaha/ftpmanage.git'

原因:

本地仓库为空

解决方法:

$ git add *

$ git commit -m "init files"

 

错误:

$ git push -u origin master Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts. To git@github.com:hahaha/ftpmanage.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:hahahah/ftpmanage.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.

解决方法:

git pull 之后再 push

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值