git报错:
$ git push -u origin master
To git@github.com:***.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:***.git
hint: Updates were rejected because the tip of your current branch is behin
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.
git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。有两种方法可解决这个问题:
方法1:强行将代码推到github仓库里面去(推荐,省时省力)
git push -f origin master //直接强推,即利用强覆盖方式用你本地的代码替代github仓库内的内容
方法2:先把git的东西fetch到你本地然后merge后再push(输入命令较多,有点慢)
git fetch
git merge //这两条命令等价于git pull
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
之后再重新git pull下,最后git push你的代码吧。参考:这里。