29

I keep getting this error when I try to push to GitHub from VScode. I've pushed before to that repository following the exact same steps I am following now. Can't find an answer to what is the reason for this error?

Tsabary
  • 2,138
  • 1
  • 17
  • 45

9 Answers9

43

You get this try running pull first to integrate your changes whenever your local branch and your remote branch are not on the same point, before your changes.

remote branch commits : A -> B -> C -> D
local branch commits  : A -> B -> C -> Local_Commits 

Now clearly, there's a change D that you don't have integrated locally. So you need to rebase, then push, which will lead to the following.

remote branch commits : A -> B -> C -> D
local branch commits  : A -> B -> C -> D -> Local_Commits 

To solve your issue, do the following

git pull --rebase origin branchname
git push origin branchname
Nizar
  • 1,734
  • 1
  • 19
  • 21
5

One possible reason that you get the "Failed to push some refs" error is that you do not have enough permission to push to the current branch (probably master). You need to ask project maintainers to give you enough permission or you need to push your changes to another branch and make a merge/pull request.

Vahid
  • 5,516
  • 4
  • 34
  • 51
3

VS Code will display this message for a bunch of different errors where the remote rejects your commits, not just the issue described.

In my case, I had the error "The object will increase this repository size by 38642606 bytes (the limit is 10485760 bytes)" because I was committing a large file to the repository.

If you are encountering this issue AND it's not because you're out of sync with remote (as per top answer), I suggest actually using the Git CLI, it will show you a more useful error message.

Mjr
  • 56
  • 3
3

In my case, I used git push --no-verify. It worked

2

I was getting this message in my Azure DevOps Repos environment because the server had a branch policy on the master branch that requires pull request approval and I was trying to push to master directly. Even after pull and rebase the same message appears. I don't think VS Code really knows how to interpret this specific error coming back from the server so it gives the generic message. If I try the same push with git directly it shows a remote rejected error that explains the problem. So my answer only applies in this 1 narrow case, but it can definitely cause the same error message to appear when pushing in VS Code.

Matthew MacFarland
  • 1,714
  • 2
  • 17
  • 24
1

I got a similar issue, try these below cases any one of the below cases might solve your issue:

  1. After resolving merge conflicts, it's expecting you to commit your changes:
    git commit -m "resolved merge conflicts or any other message"
  2. Click on "git pull from" option in VSCode and resolve conflicts, if any.
  3. git pull --rebase origin develop.
סטנלי גרונן
  • 2,849
  • 23
  • 46
  • 65
sai
  • 179
  • 2
  • 7
1

In my case, I got it because (in a personal) project I pushed a commit, and then I added a change and I did a git commit --amend.

So I ended up having two commits with the same title but different ids. One on origin/HEAD and one in HEAD -> master. In that case if it's on a personal project, i.e. a project that nobody else is pushing commits, it's ok to push --force.

Other wise check this post: How do I push amended commit to the remote Git repository?

Fotios Tsakiris
  • 804
  • 1
  • 10
  • 18
1

Sometimes it's not your fault. Don't forget to check https://www.githubstatus.com/ if you're getting completely unexpected errors. This is pretty bad, but at least they're all only yellow and not red

enter image description here

claudekennilol
  • 867
  • 2
  • 11
  • 22
0

This issue could be related to local Git hooks, try the following command and it should work :

git pull --rebase origin <yourBranchName>
git push origin <yourBranchName>
git push --no-verify
Suraj Rao
  • 28,850
  • 10
  • 94
  • 99
lokeshj
  • 714
  • 4
  • 11