Steven Fisher
Steven Fisher

Reputation: 44856

git push failure with no conflict

I've read a few explanations for a broken git push, but none of them seem to cover this case.

I'm unable to push my local changes to a remote repository, even after a pull and with no conflicts.

$ git pull
Already up-to-date

$ git st
# On branch unstable
nothing to commit (working directory clean)

$ git push
To ssh://<url>
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://<url>'
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.

<url> is, of course, the real URL of my repository.

There are no changes to pull, no conflicts, and I'm not sure what else could cause this to fail.

I believe I've got everything set up correctly:

$ git remote -v
origin  ssh://<url> (fetch)
origin  ssh://<url> (push)

$ git branch -v
  master   175a09d [behind 18] openReview must now be called from thread other than main.
* unstable c9e5cab Progress on attachments.

In the past, I've just deleted my local repository. However, this is happening more frequently.

  1. What caused this to happen?
  2. How can I avoid it in the future?
  3. How am I supposed to fix this?

Upvotes: 5

Views: 577

Answers (3)

Giorgio Previtera
Giorgio Previtera

Reputation: 383

I had the same issues these days, you are trying to do a 'non-fast-forward' update. As you can read in the help typing git push --help and reading the 'note about fast-forwards', you started locally a history that is different from the one in you repo. If you are SURE that you local branch is up to date, you can force a push using git push --force to overwrite your remote repo with your local.

Upvotes: 0

Jack Edmonds
Jack Edmonds

Reputation: 33161

Git is basically complaining that your local history is different from the remote history. This can happen if you rebase your branch, or generally do anything that modifies already committed revisions after you've pushed them.

To fix it, just do

git push -f #Warning, this will essentially clobber revisions on origin with your local revisions.

The important bit is that "non-fast-forward updates were rejected." Normally, Git can just copy your revisions over to the remote repository and bump HEAD up to the most recent revision. However, if your history is different (you edited a revision in your local after you had pushed it to the remote) it can't just fast forward.

Upvotes: 1

DanR
DanR

Reputation: 322

Full disclosure - my git is a little rusty so this may not be 100% correct.

It appears that your local 'master' branch is behind the 'origin' master branch. When you run 'git push' it will attempt to update all the remote branches with your corresponding local branches. To just push your current branch, try git push origin unstable. Also, if you want your local master branch to get up-to-date, checkout the master branch and run git pull.

Upvotes: 4

Related Questions