46

In Visual Studio 2019 I have "Unpushed Commits" as seen below:

enter image description here

When I try to push them I get the error and this is what it looks like on the GUI: enter image description here

note: the yellow label with "Failed to push..." is not clickable.

The Output from Source Control - Git is as follows: enter image description here

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'

Sniipe
  • 1,116
  • 3
  • 13
  • 28

18 Answers18

18

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.
Vy Do
  • 46,709
  • 59
  • 215
  • 313
10

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.

Sudhir Yadav
  • 124
  • 1
  • 9
8

I had the same issue in VS2019.

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

Error from 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.

Pavenhimself
  • 527
  • 1
  • 5
  • 18
  • 1
    This is the answer (or, at least a workaround) to the **actual** question: where are the "details" promised in the GUI error message? – Bob Sammers May 26 '21 at 11:51
4

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

4

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.

LQd
  • 61
  • 3
2

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.

Ash K
  • 1,802
  • 17
  • 44
2

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

enter image description here

MubarakZade
  • 127
  • 4
  • 9
1

Changing Git Options>Source Control>Git Repository Settings>Remotes Url to project URL worked for me.

Aasish
  • 377
  • 5
  • 18
1

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!

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

Fuzzy Analysis
  • 3,168
  • 2
  • 42
  • 66
1

If nothing shows up in the output, check 'show output from' set

Andre
  • 11
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '22 at 15:38
1

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

enter image description here

James Burnett
  • 151
  • 1
  • 5
1

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.

1

in my problem , i have created branch then i deleted it from local but i didnot delete it from remote then i create another one with the same name then this problem appear .. so you can delete old branch from local and remote

1

Make sure that the branch being pushed has the exact name (case sensitive) as the origin branch you are pushing to.

0

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

Masoud
  • 260
  • 2
  • 9
0

In my case there was a file (not included in the solution, but it was in the folder) that was bigger than 100 MB). Moved the file, retried with "Push" and it worked.

Andrea Antonangeli
  • 1,242
  • 1
  • 21
  • 32
0

For me the issue was a windows casing issue, the origin already had a folder structure, e.g. Feature/ I created a new branch under feature/ (lowercase) but Visual studio could only resolve it under the Upper case Feature/

Make sure your teams create branches with lower case format!

Adam
  • 613
  • 1
  • 8
  • 10
0

I faced similar issue, actual issue was with the feature branch name, which was already used so I renamed and pushed, it worked.

Santhosh UJ
  • 28
  • 1
  • 9