关于本地代码提交github的问题

图片描述

图片描述

我在本地建了一个文件夹,文件夹放入一个文档。然后具体步骤如上图,先设置ssh-key,然后按照一般步骤git init ,git add . ,git commit -m 'dd',git remote add origin,git pull origin master,git push oritin master,尝试了好几次不同的步骤和方法都不行,没有上传代码成功。我用的https的github地址。也试过git push --upstream这个也不行
报错:
failed to push some refs to 'https://github.com/gipal/dd.git'
Updates were rejected because the tip of your current branch is behind
its remote counterpart. Integrate the remote changes (e.g.
'git pull ...') before pushing again.
See the 'Note about fast-forwards' in 'git push --help' for details.

试了git pull也不行,麻烦大神帮忙解决,感激不尽

阅读 2.7k
4 个回答

执行git push origin master报错error: failed to push some refs to...

  解决办法:大部分是由于github中的README.md文件不在本地代码目录中导致的, 先通过git pull --rebase origin master进行合并,再通过git push -u origin master上传

这个原因是因为你本地的仓库和远程的仓库是两个独立的库,假如你之前是直接clone的方式在本地建立起远程github仓库的克隆本地仓库就不会有这问题了。

解决办法: 在pull命令后紧接着使用--allow-unrelated-history选项

git pull origin master --allow-unrelated-histories

楼主可以试试这个命令 git push -u origin master -f

直接 git pull origin master 再提交试试。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题