For Ruby on Rails project pull request, git push to my fork failing

旧街凉风 提交于 2019-12-23 04:53:28

问题


I made fixes and tests, git commit -a, updated my branches and now I'm trying to push to a GitHub fork I had previously made:

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 (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

I'm guessing the reason for this issue is the fork is a little outdated (by a week maybe). I've made other pushes to the fork though that I don't want to lose. What do I do here?


回答1:


While on a master branch locally:

  1. You need to add rails/rails as upstream: git remote add upstream git://github.com/rails/rails.git
  2. Now, pull with rebase (not with merge, as it will be easier to keep up with updates on rails/rails if you rebase) git pull --rebase upstream master
  3. Push the changes to your master (you will need force to push, but be careful and make sure you are OK with the changes, since previous changes will be somewhat harder to recover after this operation) git push --force origin master



回答2:


I think your branch is not up-to-date so you need to pull recent change then push your changes to remote.

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



回答3:


Your (Github) fork know nothing about upstream changes

Message states clearly

Merge the remote changes

i.e - in your Github repo you have changesets, that are not in the local repo



来源:https://stackoverflow.com/questions/13537894/for-ruby-on-rails-project-pull-request-git-push-to-my-fork-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!