如何通过git将项目上传到github以及解决git push错误:failed to push some refs to git

首先git init在本地生成.git文件
在这里插入图片描述
接着git add . 将所有文件添加到仓库
git commit -m "注释"
接着git remote add origin "此处是你github中仓库地址"
在这里插入图片描述
最后输入

git push -u origin master

如果新建的仓库是空的,则要加上**-u** ,等远程仓库有内容时,下次再加入只需要:

git push origin master

由于我添加了三个工程项目到同一仓库中,故添加第一个项目时按照此方法成功了,在git第二个项目时,执行到最后一步出现报错

error: failed to push some refs to 'git@github.com:zuiwangzuo/myDemoPro.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.

解决方法:出现此问题的原因是github中刚上传的第一个项目不在第二个项目中,所以只需先将远程仓库中代码pull到本地再执行push操作即可。

 git pull --rebase origin master

再次push

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值