Home git How to fix a GIT error

How to fix a GIT error

Author

Date

Category

Error:

$ git push form1 master To
https://github.com/prochka/form-captchaNumber-ajax ! [rejected]
master – & gt; master (fetch first) error: failed to push some refs to
https://github.com/prochka/form-captchaNumber-ajax

hint: Updates were rejected because the remote contains work that you
do

hint: not have locally. This is usually caused by another repository
pushing

hint: to the same ref. You may want to first integrate the remote
changes

hint: (e.g., ‘git pull …’) before pushing again.

hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for
details.

The GitHub repository has just been created and there are no changes there


Answer 1, authority 100%

You have changes there that are not in the local repository. You did not make an empty repository on Github, but with an initial commit. The local repository has its first commit and these commits, as you understand, are not equal (in fact, you just have two different repositories).

Just delete the .git folder locally, re-create the repository (git init ), write upstream (git remote add ... ) and after that you can do git pull . Should help 🙂


Answer 2, authority 86%

Translating https://stackoverflow.com/a/44442333/5574962

I had the same error when I first created a local repository. Then I switched to GitHub and created a new repository there. Then executed

git remote add origin & lt; repository url & gt;

And when I tried push / pull, I got the same fatal: unrelated_histories error.
And here’s how I fixed it:

git pull origin master --allow-unrelated-histories
git merge origin origin / master
... here we execute the add and commit commands ...
git push origin master

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions