Is there a good way to explain how to resolve \"! [rejected] master -> master (fetch first)\'
\" in Git?
When I use this command $ git push or
The reason it happened in my case was when creating the GitHub rep link, I initialized it with README file
While creating Git remote do not initialize it with README file otherwise it would show err
Don't do that & it will definitely work fine Instead initialize it with the readme file if you wish to after pushing to the master branch
Its Simple use this command:
git push -f origin master
and it will get your work done
This worked for me, since none of the other solutions worked for me. NOT EVEN FORCE!
https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-using-the-command-line
Just had to go through Git Bash
cd REPOSITORY-NAME
git add .
git commit -m "Resolved merge conflict by incorporating both suggestions."
Then back to my cmd and I could: git push heroku master
which in my case was the problem.
--force
option worked for me I used git push origin master --force
The answer is there, git is telling you to fetch first.
Probably somebody else has pushed to master already, and your commit is behind. Therefore you have to fetch, merge the changeset, and then you'll be able to push again.
If you don't (or even worse, if you force it by using the --force
option), you can mess up the commit history.
EDIT: I get into more detail about the last point, since a guy here just gave the Very Bad Advice of using the --force
option.
As git is a DVCS, ideally many other developers are working on the same project as you, using the same repository (or a fork of it). If you overwrite forcefully with your changeset, your repository will mismatch other people's, because "you rewrote history". You will make other people unhappy and the repository will suffer. Probably a kitten in the world will cry, too.
TL;DR
--force
option. You asked for the former, though. Go for 1) always, even if you will always use git by yourself, because it is a good practice.
Use this command:
git push -f origin master --force