简体   繁体   中英

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

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?

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

Your (Github) fork know nothing about upstream changes

Message states clearly

Merge the remote changes

ie - in your Github repo you have changesets , that are not in the local repo

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM