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

本文介绍如何将本地Git仓库与GitHub上的远程仓库进行关联同步。包括创建远程仓库、关联本地仓库、推送本地更改到远程的过程及遇到的问题解决办法。

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 'git@github.com: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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值