[GIT] - 项目上传github时版本不同问题解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuskzuo/article/details/79852253

github创建并关联


在本地创建了一个Git仓库后,又想在GitHub创建对应仓库,并且让这两个仓库进行远程同步关联同步。

  • 在github上创建新的仓库。
  • 接着可以克隆线上新仓库,或者关联本地和线上仓库。

    • 线上关联,在本地的homework仓库下运行命令,需要替换为自己的github账号:

      git remote add origin git@github.com:May7th/homework.git
    • 把本地库的所有内容推到远程仓库

      git push -u origin master

      一般这样就可以了。
      但是我提前在远程库添加了文件。接着我又进行了如下操作:

    • 提交所有文件
      git add .
      git commit -am "init"
      

    在push 的时候发现不成功,出现以下问题。

    error: failed to push some refs to '[email protected]:May7th/homework.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.
    changzhendeMacBook-Pro:homework changzhen$ git push -u master
    fatal: 'master' does not appear to be a git repository
    fatal: Could not read from remote repository.

    最后发现是文件版本不同,强制覆盖已有的分支后上传成功,可能会有文件丢失情况。

git push -u origin master -f 

猜你喜欢

转载自blog.csdn.net/wuskzuo/article/details/79852253