Git with Visual Studio

2017/06/302 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Common Issue with Git in Visual Studio
  3. Conclusion

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:

  1. After checking out the target branch, always pull first, then perform other operations like merge or push.

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

  3. Restart Visual Studio — this might work.

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