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
You just have to mention your branch name along with your remote name.
git fetch origin
git merge origin/master
This worked for me:
$ git add .
$ git commit -m "commit"
$ git push origin master --force
Follow the steps given below as I also had the same problem:
$ git pull origin master --allow-unrelated-histories
(To see if local branch can be easily merged with remote one)
$ git push -u origin master
(Now push entire content of local git repository to your online repository)
Your error might be because of the merge branch.
Just follow this:
step 1 : git pull origin master
(in case if you get any message then ignore it)
step 2 : git add .
step 3 : git commit -m 'your commit message'
step 4 : git push origin master
As it is stated in the Error message you have to "fetch first." This worked for me. Use the command:
git fetch origin master
Then follow these steps to merge:
git pull origin master
git add .
git commit -m 'your commit message'
git push origin master
Sometimes it happens when you duplicate files typically README sort of.