I"m trying to push my project (all files in a new repository). I follow the steps but when I push with git push -u origin master I get this error:

! master -> master (non-fast-forward)error: failed to push some refs to "git
github.com:asantoya/projectnewbies.git"To prevent you from losing history, non-fast-forward updates were rejectedMerge the remote changes (e.g. "git pull") before pushing again. See the"Note about fast-forwards" section of "git push --help" for details.I got this error many times and can"t figure out what to do.

You are watching: ! [rejected] master -> master (fetch first)


*

*

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.


*

*

git push -f origin masteruse brute force ;-)Most likely you are trying to add a local folder that you created before creating the repo on git.


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 masterrepository URL is got from here on project github page :

*

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

git initgit add .git commit -m "update"Then push :

git push
If git pull does not help, then probably you have pushed your changes (A) and after that had used git commit --amend to add some more changes (B). Therefore, git thinks that you can lose the history - it interprets B as a different commit despite it contains all changes from A.

B / ---X---AIf nobody changes the repo after A, then you can do git push --force.

However, if there are changes after A from other person:

B / ---X---A---Cthen you must rebase that persons changes from A to B (C->D).

B---D / ---X---A---Cor fix the problem manually. I didn"t think how to do that yet.


Share
Follow
answered Apr 30 "14 at 9:05
Alexander VolkovAlexander Volkov
7,00711 gold badge4242 silver badges3838 bronze badges
Add a comment |
9
i had created new repo in github and i had the same problem, but it also had problem while pulling, so this worked for me.

but this is not advised in repos that already have many codes as this could mess up everything

git push origin master --force
Share
Follow
edited Dec 7 "15 at 11:21
answered Dec 7 "15 at 9:55
Muneef MMuneef M
1,0341515 silver badges1515 bronze badges
1
Add a comment |
9
use this command:

git pull --allow-unrelated-backgrounds

like:

git pull --allow-unrelated-histories origin master

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


Share
Folshort
answered Sep 16 "16 at 15:12
Umar FarooqUmar Farooq
9111 silver badge11 bronze badge
Add a comment |
9
WARNING:

Going for a "git pull" is not ALWAYS a solution, so be carefull. You may face this problem (the one that is mentioned in the Q) if you have intentionally changed your repository history. In that case, git is confusing your history changes with new changes in your remote repo. So, you should go for a git push --force, because calling git pull will undo all of the changes you made to your history, intentionally.


Share
Follow
edited Jul 15 "19 at 15:16
answered Sep 15 "16 at 12:45
GuptaGupta
7,77244 gold badges3030 silver badges5757 bronze badges
Add a comment |
6
This is because you did some changes in your master so the project ask you to pull first. If you want to push it anyway you can use brute force by typing this:

git push -f origin masterRemember to first commit your changes:

git add .git commit -m "Your commit message"
Share
Follow
answered Mar 20 "18 at 16:55
gtechgtech
50711 gold badge88 silver badges2222 bronze badges
Add a comment |
5
Try this command: "git pull origin master"

It worked for me.

Check this link: https://help.github.com/articles/dealing-with-non-fast-forward-errors


Share
Folshort
answered Mar 25 "14 at 15:10
firefly28firefly28
9911 silver badge33 bronze badges
Add a comment |
4
You need to do

git branchif the output is something like:

* (no branch)masterthen do

git checkout masterMake sure you do not have any pending commits as checking out will lose all non-committed changes.


Share
Follow
edited Sep 4 "13 at 15:11
answered Sep 3 "13 at 21:04
cagecage
10311 silver badge88 bronze badges
Add a comment |
4
! master -> master (non-fast-forward)

Don’t panic, this is extremely easy to fix. All you have to do is issue a pull and your branch will be fast-forward:

$ git pull myrepo master

Then retry your push and everything should be fine:

$ git push github master


Share
Folshort
answered Feb 10 "14 at 11:52
user3292712user3292712
3733 bronze badges
Add a comment |
4
This happened to me when I was on develop branch and my master branch is not with latest update.

So when I tried to git push from develop branch I had that error.

I fixed it by switching to master branch, git pull, then go back to develop branch and git push.

$ git fetch && git checkout master$ git pull$ git fetch && git checkout develop$ git push
Share
Follow
answered Aug 17 "16 at 18:17
Jonn Marc VistalJonn Marc Vistal
1061010 bronze badges
Add a comment |
3
I had this problem on a development machine. The dev branch was pushing fine but thethe master branch gave me (while git pushing when being on the dev branch):

! master -> master (non-fast-forward)So I tried:

git checkout mastergit pullWhich gave me:

You asked me to pull without telling me which branch youwant to merge with, and "branch.master.merge" inyour configuration file does not tell me, either.I found out the master branch was missing native .git/config and added:


remote = origin merge = refs/heads/masterAfterwards git push also worked fine on the dev branch.


Share
Folshort
answered Sep 3 "14 at 13:10
kqwkqw
18.3k1111 gold badges6161 silver badges9494 bronze badges
Add a comment |
3
My Remote was not in sync with the local so this worked for me

git pull --rebase

and make sure when you do git pull again it should say Already up to dateand now you are ready to push to origin

assuming you have already git remote add origin remote repository URL

do

`git push origin master` The Screenshot says it all

*

Alternatively you can do this

git stash (stores uncommited work temporarily)git pull (make your local and remote in sync)git stash pop (get back you uncommited changes )git push
Share
Follow
edited Dec 6 "19 at 4:31
answered Mar 6 "19 at 4:02
Mahesh JamdadeMahesh Jamdade
8,18344 gold badges5757 silver badges7575 bronze badges
Add a comment |
1
I had same as issue.I use Git Totoise.Just Right Click ->TotoiseGit -> Clean Up .Now you can push to GithubIt worked fine with me :D


Share
Follow
answered Dec 22 "14 at 12:39
Son Nguyen ThanhSon Nguyen Thanh
1,0891515 silver badges1919 bronze badges
Add a comment |
1
This is because you have made conflicting changes to its master. And your repository server is not able to tell you that with these words, so it gives this error because it is not a matter of him deal with these conflicts for you, so he asks you to do it by itself. As ?

1- git pullThis will merge your code from your repository to your code of your site master.So conflicts are shown.

2- treat these manualemente conflicts.

3-

git push origin masterAnd presto, your problem has been resolved.


Share
Follow
answered Apr 4 "16 at 19:51
Paulo Linhares - PackappsPaulo Linhares - Packapps
1,1461313 silver badges1818 bronze badges
Add a comment |
1
This may also be caused due to some name error caused while giving name to the Repo.If any of the above answers haven"t functioned .This worked for me:

Delete that repo and create a new one and try the following commands again:

cd "Local Directory Path"git remote add origin *your_git_name.git*git push -u origin masterif add origin shows already exists use this instead:

git remote set-url origin *your_git_name.git*
Share
Follow
answered Mar 29 "20 at 7:58
Harshal SGHarshal SG
27322 silver badges66 bronze badges
Add a comment |
0
The only i was able to resolve this issue was to delete the local and git repo and create the same again at both ends. Works fine for now.

See more: Give Me My Baby Cast & Crew, The Stranger Inside (Give Me My Baby)


Share
Folshort
answered Mar 26 "13 at 4:27
Akash Kumar SharmaAkash Kumar Sharma
54277 silver badges1717 bronze badges
1
Add a comment |
0
If anyone has this error while trying to push to heroku then just replace "origin" with "heroku"like this:git push -f heroku master


Share
Follow
answered Mar 11 "19 at 0:11
Vadim MalakhovskiVadim Malakhovski
15911 silver badge44 bronze badges
Add a comment |
0
Try this, in my case it works

git rebase --abort


Share
Folshort
answered Mar 20 "20 at 18:29
Ahmer AfzalAhmer Afzal
46222 gold badges1111 silver badges2323 bronze badges
Add a comment |
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Not the answer you're looking for? Browse other questions tagged git push or ask your own question.


The Overflow Blog
Featured on Meta
Linked
743
There is no tracking information for the current branch
41
git error when trying to push to remote branch
12
EGit: cannot push, cannot pull
2
Why won't git bash allow me to push to my remote repo?
1
Git push error, head of distant repo is behind local
2
cannot push to bitbucket 403 "authentication failed"
1
Git Push/Pull VS 2015 Issue
Related
854
Git for beginners: The definitive practical guide
1012
Git workflow and rebase vs merge questions
743
Git pull a certain branch from GitHub
437
Heroku: How to push different local Git branches to Heroku/master
786
Cleaning up old remote git branches
3367
Git: Message 'src refspec master does not match any' when pushing commits in Git
156
What does "Git push non-fast-forward updates were rejected" mean?
1493
How do I properly force a Git push?
1294
Git merge hotfix branch into feature branch
431
Updates were rejected because the tip of your current branch is behind its remote counterpart
Hot Network Questions more hot questions
Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Stack Overflow
Products
Company type of
Stack Exchange Network-related
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.23.40286


Stack Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.