git和github建立关系

问题描述

  1. 在github建立了项目
  2. 本地已经存在了一个项目,所以就没有从github clone空项目 直接在本地使用了git init
  3. 建立连接 git remote add origin *****此处是github上的项目地址
  4. 然后 直接 git add ; git commit 了
  5. 然后 就 git push origin master 于是就出现了下面的问题
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/*****.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

github上的版本里有readme文件和本地版本冲突,
解决方案是:强制覆盖已有的分支
使用git push -u origin master -f搞定。

正确的做法是

在第3步建立了联系之后,使用git pull -f --all
或者中规中矩,不要在本地git init 在github上clone之后 把原来的项目 移动过去就好了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容