Git push complaining about non-fast-forward, even though remote has been pulled

只愿长相守 提交于 2019-12-03 16:46:40

Here's one way to get synced up.

First, Commit any changes, then use git log to note any commits you wanted to push.

Next reset your master to match the remote like this:

git checkout master
git reset --hard remotes/rubix/master 

Finally, cherry pick the commits you wanted to keep

Example:

git cherry-pick 111aaa111
git cherry-pick 123abc123

Now pushing should work.

git push rubix master

I'm not sure how you ended up on no branch. You may be in the middle of a rebase. You may have checked out a commit directly. In any event, this is likely the cause of your pushing woes. Check git reflog to see if it shows any obvious cause and git log to see where you are. Look at the changed files with git diff to decide if you want to keep them (and use git add . && git stash if you do). Then, once you are sure you don't need any changes or any of your current history, git checkout master to get back.

If it still not work, you may probably need to configure your git to accept alias branch name

git config --global push.default upstream

By default, if your remote branch name is origin/master, git will only accept your push if your local tracking branch name is master. If you create a local tracking branch as master_xxx, git will not accept your push unless you modify your push.default configuration to upstream.

I had this same problem and came across this question, so I thought I would post the solution to my problem.

NOTE: I am using git on Windows.

I had accidentally checked out my local branch with different casing: "Develop" instead of my usual "develop." Nothing I did would correct the issue (even after checking out the branch with the correct casing) until I followed these steps:

  1. Checkout out the branch with the correct casing "develop"
  2. Make any change, add/commit
  3. Now you can push without being rejected
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!