'Visual studio 2019 "Error encountered while pushing to the remote repository: Failed to push to the remote repository..."
In Visual Studio 2019 I have "Unpushed Commits" as seen below:
When I try to push them I get the error and this is what it looks like on the GUI:

note: the yellow label with "Failed to push..." is not clickable.
The Output from Source Control - Git is as follows:

The output window doesn't show me any useful details. Am I looking in the wrong place? Is there a better place to see the actual error?
The answer in this case is that the policy on the branch 'develop' does not allow direct pushes. I was kinda hoping that the error in the output would state something like 'Failed to push due to a policy constraint on the branch'
Solution 1:[1]
I was getting the same error and after trying lot of things, I found the solution.
Solution - Go to your GitHub account >> Profile >> Emails >> "Keep my email addresses private" - >> Uncheck this option.
Note : - This error may occur due to various reasons. This is the one of reason to fail the Push operation. To know the exact reason check your Output window in Visual Studio.
Solution 2:[2]
I had the same issue in VS2019.
I tried in CMD and got a better error message, which VS2019 did not provide
I had accidently commited a zip file in one commit, but removed it in the next commit.
So I had to reset both commits and remove the zip from the first commit. Then I could stage both commits and push them.
Solution 3:[3]
I had very same issue, different reason. I was pushing completely new branch from local, so I knew the branch policy could not be the culprit. But still it didn't allow me to push it, hence I needed some real error message. Trying to push from command line did the trick, unfortunately VS doesn't show these details.
You do not have permission to create ref 'refs/heads/XYZ...'. Please ensure the ref naming convention being used is allowed in this repository.
Indeed, I missed feature/ prefix enforced by latest repo policy change... So just another issue to check in case of issues.
Solution 4:[4]
Had the same issue. Look at the Branch policies. Probably it needs approval or pull request.
Solution 5:[5]
For me, I was working off of my local feature branch that I cloned from master that looked like this:
feature/MyBranchName
I was trying to push those changes to origin, but looks like a recent policy change prohibited pushing to feature branches which kept on throwing this error:
"Error encountered while pushing to the remote repository: Failed to push to the remote repository. See the Output window for more details."
This command gave me the clue to the problem:
git push origin feature/MyBranchName
(Remember to include the feature)
The message was this:
Total 0 (delta 0), reused 0 (delta 0)
To https://mycompanyname.visualstudio.com/DefaultCollection/TeamProjectName/_git/MyProjectName
! [remote rejected] feature/MyBranchName -> feature/MyBranchName (TF402455: Pushes to this branch are not permitted; you must use a pull request to update this branch.)
error: failed to push some refs to 'https://mycompanyname.visualstudio.com/DefaultCollection/TeamProjectName/_git/MyProjectName
My solution to this was to to merge changes from my local feature into local development branch, push the development changes to origin and using that development branch, make a PR to whichever branch I wanted to push these changes to.
Solution 6:[6]
Changing Git Options>Source Control>Git Repository Settings>Remotes Url to project URL worked for me.
Solution 7:[7]
I had to set my git proxy, since I was behind a company firewall and using a proxy for http/https:
- I opened a command prompt (and git was already installed on my Windows Server 2016 Dev box)
- Typed in the following command after finding the server ip and port for my web proxy:
git config --global http.proxy http://<ip address>:<port> - Typed in the following:
git clone <clone address from Azure DevOps> - Worked like a charm!
P.S. I stole my answer from a similar Server Fault answer here: https://serverfault.com/questions/663504/can-browse-but-cant-ping
Solution 8:[8]
If nothing shows up in the output, check 'show output from' set
Solution 9:[9]
This happened to me & it wasn't creating a remote branch in my repo.
I was able to get around this in visual studio by going to Git->Manage Branches->highlight my branch & right click, "Unset upstream branch".
Solution 10:[10]
I was also facing the same problem. I tried to push from git bash. I got the below error message.
"(RefNames consisting of 40 hex characters are not allowed.)"
The character length of my feature branch name was greater than 40 characters. Because of this I was getting below error "Error encountered while pushing branch to the remote repository: Failed to push to the remote repository. See the Output window for more details."
I renamed my feature branch name to 40 characters and tried to push. It worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow



