Git with Visual Studio
Table of Contents
Introduction
This post covers a common issue encountered when using Git within Visual Studio and provides steps to resolve it.
Common Issue with Git in Visual Studio
Merge or Commit Error
If you're using Visual Studio's Git merge to merge code from a source branch to a target branch and there are new commits on the target branch, you might see the following error:
An error occurred. Detailed message: 2 uncommitted changes would be overwritten by merge
You'll probably still see this error after trying to pull from the target branch a couple of times. I think this might be a bug when using Visual Studio's Git integration, but some people say it might be caused by a locked file. Either way, it is something that should work, but Git in Visual Studio is not handling it correctly. The following are fixes I have tried that work so far:
-
After checking out the target branch, always pull first, then perform other operations like merge or push.
-
Although #1 should work most of the time, if you forgot to pull or even after you pull someone else pushes their changes, you might still see the above error.
-
Restart Visual Studio — this might work.
-
Open the command line from your current source folder and type the following:
git status
git pull
Conclusion
When encountering merge or commit errors in Visual Studio's Git integration, the most reliable fix is to always pull before performing other operations. If the issue persists, try restarting Visual Studio or using the command line directly.