Branch Error VSTS DevOps

05.08.2020

error: Cannot switch because there are uncommited changes. Commit or undo your changes before you switch branches.


Solution:

I used the git command prompt to resolve the issue. I can't guarantee that it's the best way or the only way, but it worked for me in Visual Studio 2013.

Under Changes in the Team Explorer, choose Open Command Prompt.

In the command prompt type:

git status

It will list the files that are open for change.

Copy off those files (just in case), then you can then discard the changes in the working directory in the command prompt.

git checkout -- mysubdir\myfile.ext

Don't attempt to change branches in Visual Studio, it still won't work!

Instead at the command prompt switch to the branch in question.

git checkout branchname

When you go back to Visual Studio it will prompt you to reload the project. After that the branch will be updated correctly to the branch you chose from the command line.