对于Ruby on Rails项目拉取请求,git push to my fork失败

我做了修复和测试, git commit -a ,更新了我的分支,现在我正在尝试推送到我之前做过的GitHub分支:

 vagrant@rails-dev-box:~/rails$ git push mine my_fix Username for 'https://github.com': myusername Password for 'https://myusername@github.com': To https://github.com/myusername/rails.git ! [rejected] my_fix -> my_fix (non-fast-forward) error: failed to push some refs to 'https://github.com/myusername/rails.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. 

我猜这个问题的原因是fork有点过时(可能是一周)。 虽然我不想输,但我已经做了其他推动。 我该怎么办?

在本地master分支上:

  1. 你需要在上游添加rails / rails: git remote add upstream git://github.com/rails/rails.git
  2. 现在,使用rebase(而不是合并,因为如果你重新调整就更容易跟上rails / rails上的更新) git pull --rebase upstream master
  3. 将更改推送到主服务器(您需要强制推送,但要小心并确保您对更改没有问题,因为此操作之前的更改将更难以恢复) git push --force origin master

我认为您的分支机构不是最新的,因此您需要提取最近的更改,然后将更改推送到远程。

  $git pull --rebase branch_path $git push remote_name branch_name 

你的(Github)分叉对上游变化一无所知

消息明确说明

合并远程更改

即 – 在您的Github回购中,您有变更集不在本地仓库中