I\'m trying to push my project (all files in a new repository). I follow the steps but when I push with git push -u origin master
I get this error:
This may also be caused due to some name error caused while giving name to the Repo. If any of the above answers haven't worked .This worked for me:
Delete that repo and create a new one and try the following commands again:
cd 'Local Directory Path'
git remote add origin *your_git_name.git*
git push -u origin master
if add origin shows already exists use this instead:
git remote set-url origin *your_git_name.git*
i had created new repo in github and i had the same problem, but it also had problem while pulling, so this worked for me.
but this is not advised in repos that already have many codes as this could mess up everything
git push origin master --force
This is because you did some changes in your master so the project ask you to pull first. If you want to push it anyway you can use brute force by typing this:
git push -f origin master
Remember to first commit your changes:
git add .
git commit -m "Your commit message"
The only i was able to resolve this issue was to delete the local and git repo and create the same again at both ends. Works fine for now.
As the error message says: git pull
before you try to git push
. Apparently your local branch is out of sync with your tracking branch.
Depending on project rules and your workflow you might also want to use git pull --rebase
.
WARNING:
Going for a 'git pull
' is not ALWAYS a solution, so be carefull. You may face this problem (the one that is mentioned in the Q) if you have intentionally changed your repository history. In that case, git is confusing your history changes with new changes in your remote repo. So, you should go for a git push --force
, because calling git pull
will undo all of the changes you made to your history, intentionally.