尝试推送到远程分支时出现git错误

use*_*400 41 git push

我从git克隆了存储库A的主分支,并创建了自己的分支Li.我前段时间做了一些改动,把当地李的内容推到了偏远的李.

现在我已经从远程主机到本地主分支以及从本地主分支到本地Li的一些更新,我正在尝试将更新从本地Li推送到远程Li.但是,当我尝试运行时:

git checkout Li
git push origin Li
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error: failed to push some refs to 'git@github.com:anodejs/system.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)

请注意,我的本地主分支已更新(我调用了git pull origin master)并合并到本地Li分支.但是,我确实在本地Li添加了一个新文件,因此本地Li与本地主人不同(但这不应该,对吧?)

谢谢,李

Siv*_*raj 36

更新被拒绝,因为推送的分支提示在其远程后面.

git config --global push.default current
Run Code Online (Sandbox Code Playgroud)

尝试上面的命令将当前分支设置为默认值

git push
Run Code Online (Sandbox Code Playgroud)

  • 注意这个命令改变了`git push`的基本行为,这通常是,但并非总是如此.想知道这些行为是什么的用户可以看到[这个问题](http://stackoverflow.com/questions/13148066/warning-push-default-is-unset-its-implicit-value-is-changing-in- git-2-0)或[这个问题](http://stackoverflow.com/questions/11872984/what-is-the-difference-between-git-push-default-current-and-push-default-upstrea/ 11873386#11873386). (10认同)

Chr*_*her 29

找到差异git fetch && git log Li..origin/Li.我猜你Li自从上次推动以来你已经重新定位或以其他方式重新开始,但是这个命令应该告诉你遥控器中究竟是什么不在本地.您可以使用三点语法找到(但不是两者)中的内容:git log Li...origin/Li.

如果期望差异,那么只需合并git merge origin/Li然后git push.如果更改是不需要的,请用git push -f origin Li.覆盖遥控器.只有在您想放弃远程更改时才执行此操作.