-1

I created a new repository on GitHub and pushed some work on to its master branch but somehow when I again tried to commit and push some stuff onto it, the terminal said that the git doesn't exist. So I git init another directory with almost the same file and added origin again using git remote add origin https://github.com/hassansuhaib/recipe-app and now when I push the work it gives this error. Error How can I overwrite the existing files? P.S. I am a code newbie

dstrants
  • 7,423
  • 2
  • 19
  • 27
hassansuhaib
  • 267
  • 3
  • 14
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd May 03 '20 at 18:08

2 Answers2

2

Whenever there is difference of work in the repository and local machine(repo has something extra then local machine) or there are some untracked files on your repo, what I normally do is git pull first to match all the work and on repo and the local machine then git push -u origin master. I hope this helps you in the future.

Ahmad Anis
  • 2,322
  • 4
  • 25
  • 54
1

Never mind! I used git push --set-upstream origin master --force

hassansuhaib
  • 267
  • 3
  • 14
  • 1
    The force pushes regularly won't make things any better. You should try to pull the changes from the remote repo as introduced by the answer above so that you can maintain integrity between the changes you make, and the remote and local repo. – dstrants May 03 '20 at 18:07