First and simple solution:
- Try this command
git push -f origin master
. - This command will forcefully overwrite remote repository (GitHub)
Recommended Solution 1 :
- Run these commands:
git pull --allow-unrelated-histories //this might give you error but nothing to worry, next cmd will fix it
git add *
git commit -m "commit message"
git push
If this doesn't work then follow along 🔰
Solution 2 (Not Recommend) :
Will Delete all your & your team-mate's commit history. So please dont do this on professional project
Delete
.git
directory from the folder.Then execute these commands:
git init git add . git commit -m "First Commit" git remote add origin [url] git push -u origin master
OR
git push -f origin master
Only use git push -f origin master
if -u
dont work for you.
This will solve almost any kind of errors occurring while pushing your files.As you might have guessed, manipulating master is not a good thing. So simply replace it with the branch name you want to work on. Or create a new one git checkout -b fix-something