I know similar questions have already been asked.
But, I believe my issue is due to a mistake I have previously made and therefore is different: let me explain.
A similar error appears while pulling the changes from the origin. If you are trying in Intellij from the menu options, the pull might not work directly.
Go to terminal and type this command and this should work out: git pull origin master