Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am not able to push on git?

git push origin master shows an error

failed to push some refs to '[email protected]:xyz/abc.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

What is this? How to recover this?

like image 587
user12345 Avatar asked Aug 30 '10 06:08

user12345


People also ask

Why my 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.

Why can't I push code to GitHub?

To push a branch on remote, your branch needs to have the latest changes present in remote repository. If you get the failed to push error, first do git pull the branch to get the latest commits and then push it.


2 Answers

See the "pushing a branch" section from GitHub help page:

Dealing with “non-fast-forward” errors

From time to time you may encounter this error while pushing:

$ git push origin master
To ../remote/
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.

This error can be a bit overwhelming at first, do not fear.
Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch.
You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase.
While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.


Mode details on the "Note about fast-forwards" of git push, as mentioned by Michael Mrozek in the comments.

like image 56
VonC Avatar answered Sep 28 '22 05:09

VonC


In addition to VonC's answer,

In case you, intend to override the remote changes with your local,

  $git push --force

will do.

like image 34
Joe Lewis Avatar answered Sep 28 '22 04:09

Joe Lewis