Why can't I add it to my github repository on git?

Whenever I try I get this error and I can’t find exactly what it wants me to do. What is the problem?

The error specifically gives you a hint:

git pull

before pushing again.

The reason this occurs is also stated:

Updates were rejected because the remote contains work that you do not have locally.

So what you have locally doesn’t match what you want to update, so git complains about there being differences. Doing git pull will pull the changes from the remote and into/onto your local changes. This could be seemless or create merge conflicts that you then have to manage.

A common scenario when working alone on a github repo is when you create a project locally, make changes and commit them to git. Then you go on github create a repository and allow github to create a README.md file, or other files in the repo. Then when you try to push to your repo you get this error. The reason for this because your remote on github has files you don’t have locally.

The other common scenario is if someone else (or maybe you from another computer!) push changes to the repo on github, and you haven’t gotten them locally.

I tried pull it out and it didn’t work I also opened a new repo and tried on it and again it didn’t work

I solved the problem with the force command.

If git pull also didn’t work, did you get any errors? git usually is pretty good at giving you feedback when something happens, wrong, or right.

It gives the error in the photo again.

git pull gives you the error you see when you did git push? :thinking: Are you sure it wasn’t a different error?

It might not matter at this point however, if you force pushed to overwrite changes in your remote. I don’t recommend this solution most of the time, as you essentially “rewriting history” which can be very dangerous depending on the situation, or at least really confusing to anyone else working on the same repo. :slight_smile: