问题
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:
- You need to add rails/rails as upstream:
git remote add upstream git://github.com/rails/rails.git
- 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
- 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