Git: push rejected – cannot pull with rebase – local out of date

When you push a branch to a remote branch that has been updated by someone else in the meantime, without doing a pull before to update your local working directory, you will get the follow error:

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


When you try to do a pull (i.e. a shortcut for fetch and merge) you will get the following error:

$ git pull
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

You can check the local and remote logs to see the commits:

$git log origin

and for the local master log

$git log master


$git remote show origin

will show

* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (local out of date)

To solve the local out of date problem, do a fetch and merge the branches:

$git fetch origin
$git merge origin/master

Now push your changes again as you intended.

$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master rebases onto remote master
Local ref configured for 'git push':
master pushes to master (up to date)

A git pull takes the commits on origin/master (assuming your branch is master) and try to fast-forward your local branch to that point, merging any local changes. If you’ve committed locally, and those commits are meant to go after any more recent commits on the server, you can do git pull –rebase instead.

See also:
Git#push
Git Branching and Merging
Git pull

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.