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?
14 Answers
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

- 1,240
- 15
- 29

- 2,034
- 1
- 20
- 24
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.

- 6,639
- 5
- 37
- 61
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.

- 96
- 1
- 3
-
"I suggest actually using the Git CLI, it will show you a more useful error message." -> thanks, this made me realize my issue: exposing a private email address – user224567893 Dec 19 '22 at 05:31
-
An alternative to using the Git cli app to expose more detailed errors messages is to click on the "Show command output" button of the error popup in Vscode. Like @user224567893, I too had the github private email address exposure error. – Bren0man Feb 09 '23 at 00:05
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

- 992
- 2
- 13
- 26
-
Yes, it would be nice if they added a line in the error message suggesting you check your remote repo status since it can also cause that error. – Juan Perez May 17 '23 at 20:43
I got a similar issue, try these below cases any one of the below cases might solve your issue:
- After resolving merge conflicts, it's expecting you to commit your changes:
git commit -m "resolved merge conflicts or any other message"
- Click on "git pull from" option in VSCode and resolve conflicts, if any.
git pull --rebase origin develop
.

- 2,917
- 23
- 46
- 68

- 239
- 1
- 3
- 7
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.

- 2,413
- 3
- 26
- 34
In my case was because the tests were failing and the package Husky was installed. The package.json had the following config:
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run test"
}
}
So if it fails "pre-push", it won't allow you to push anything.

- 71
- 1
- 2
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?

- 1,310
- 1
- 18
- 24
it's working for this code and very useful
git push --no-verify
-
2Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney May 10 '23 at 00:11
It may happen if trying to amend an already pushed commit. If that is the case, you'll need to force push.
However in VSCode UI this may require to use Push to.. (Force)
in case you have multiple remotes (e.g. "origin" and "upstream"):

- 15,216
- 3
- 86
- 85
I had similar issue, saying refusing to allow a Personal Access Token to create or update workflow `...` without `workflow` scope
and the problem lied on the github personal access token was not including workflow
scope. Just created new token including that scope too and it works like a charm!
Reference: https://stackoverflow.com/a/67765064/1369501

- 11,452
- 5
- 41
- 45
Try running git push origin <branchname>
in the terminal. That will give you more detailed info.
In my case I got this:
remote: GitLab: Commit message does not follow the pattern '^\[(projectname)-\d{1,6}]\s.*
So it wasn't an issue with refs or heads at all. Once I fixed the commit message so it follows the required pattern, the error went away and the push went through.

- 29
- 5