Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rejected master -> master (non-fast-forward)

Tags:

git

push

NOTICE: This is never a recommended use of git. This will overwrite changes on the remote. Only do this if you know 100% that your local changes should be pushed to the remote master.

⚠️ Try this: git push -f origin master


As the error message says: git pull before you try to git push. Apparently your local branch is out of sync with your tracking branch.

Depending on project rules and your workflow you might also want to use git pull --rebase.


I've just received this error.

I created a github repository after creating my local git repository so I needed to accept the changes into local before pushing to github. In this case the only change was the readme file created as optional step when creating github repository.

git pull https://github.com/*username*/*repository*.git master

repository URL is got from here on project github page :

enter image description here

I then re-initialised (this may not be needed)

git init
git add .
git commit -m "update"

Then push :

git push

use this command:

git pull --allow-unrelated-histories <nick name of repository> <branch name>

like:

git pull --allow-unrelated-histories origin master

this error occurs when projects don't have any common ancestor.