-3

I am trying to push my project but getting rejected as errors and I am not able to understand the errors.

$ git push origin master
To https://github.com/sunil887/Angular2App.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/sunil887/Angular2App.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
Sunil Tripathi
  • 526
  • 1
  • 5
  • 12
  • Your local head is not in the last version. Do `git pull origin master` – Héctor Jan 29 '18 at 14:39
  • 4
    Possible duplicate of [Github "Updates were rejected because the remote contains work that you do not have"](https://stackoverflow.com/questions/18328800/github-updates-were-rejected-because-the-remote-contains-work-that-you-do-not-h) – Ferrybig Jan 29 '18 at 14:39
  • Don't post images of code or text. Post the code or the text as is. – axiac Jan 29 '18 at 14:42
  • What's the _exact_ error message? It's important to read those; they are usually designed to be helpful in finding and solving the problem. – ChrisGPT was on strike Jan 29 '18 at 22:24

5 Answers5

1

Do git pull before you try to push. This should either fix the issue or give you more information about what is causing the issue.

1

looks like you need to

git pull 

first.

Your remote has changes that don't exist on your local machine.

if this

Ben Hart
  • 157
  • 10
0

Here is a step-by-step procedure that you will need to do with consideration of a possible merge conflict.

  1. Do git pull to update your local repository.
  2. There might be a merge conflict after doing git pull and you will see this in your terminal. If this happens, check which files cause the conflict with git status.
  3. After fixing the merge conflicts (if any), you can now proceed with adding and committing your local changes with git add -A and git commit -m [commit message]
  4. Finally, do a git push [upstream] [branch].
Whooper
  • 575
  • 4
  • 20
0

Check your remote git. Your changes might already be there.

-1

I had the same issue:

Image of command prompt

And, to get rid of the error:

you should not use git push origin master. But, you should use git push origin main.

Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
  • main is just an alternate name to the master and there exists no real difference between master and main –  May 05 '21 at 08:07