Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push failure with no conflict

Tags:

git

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?
like image 844
Steven Fisher Avatar asked Nov 30 '11 17:11

Steven Fisher


People also ask

Why does git push fail?

failed to push some refs to errors are often caused when changes are not committed before pushing, issues with Git pre-push hook, incorrect branch name, or the local repository not being in sync with the Git repository.

What to do if git push is not working?

If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.

What does git pull with no arguments do?

Without any arguments, git merge will merge the corresponding remote tracking branch to the local working branch.


2 Answers

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.

like image 163
DanR Avatar answered Sep 25 '22 16:09

DanR


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.

like image 43
Jack Edmonds Avatar answered Sep 25 '22 16:09

Jack Edmonds