简体   繁体   中英

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'

Have few reasons for this case:

  1. Try pull , then push .
  2. Check permission (you maybe haven't permission to push, after a change). You maybe push to just protected branch.

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.

I had the same issue in VS2019.

I tried in CMD and got a better error message, which VS2019 did not provide

来自 CMD 的错误

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.

Had the same issue. Look at the Branch policies. Probably it needs approval or pull request.

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.

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.

更改 Git Options>Source Control>Git Repository Settings>Remotes Url to project URL 对我有用。

I had to set my git proxy, since I was behind a company firewall and using a proxy for http/https:

  1. I opened a command prompt (and git was already installed on my Windows Server 2016 Dev box)
  2. 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>
  3. Typed in the following: git clone <clone address from Azure DevOps>
  4. Worked like a charm!

PS I stole my answer from a similar Server Fault answer here: https://serverfault.com/questions/663504/can-browse-but-cant-ping

如果输出中没有显示任何内容,请检查 'show output from' set

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".

在此处输入图像描述

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.

在我的问题中,我创建了分支然后我从本地删除它但我没有从远程删除它然后我创建另一个具有相同名称的分支然后出现此问题..所以你可以从本地和远程删除旧分支

I had to set the value of "Bypass policies when pushing" to "Allow" for my user in ADO → Branch Security.

在此处输入图像描述

确保被推送的分支的名称(区分大小写)与您要推送到的原始分支完全相同。

There might be a policy defined on the target branch. for instant: main (TF402455: Pushes to this branch are not permitted; you must use a pull request to update this branch.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM