A few friends and I are working on a project via GitHub. We are all sharing the same branch, which may or may not be a good idea.
I edited some of the code and committed the changes. I went to push commit to GitHub (I am working with Visual Studio 2013 and it's built-in Git tool), but I got this error:
"There are new remote changes. You must pull them before you can push."
So I tried to pull the remote changes and I get this error:
"An error occurred. Detailed message: An error was raised by libgit2. Category = 21 (MergeConflict). 9 uncommitted changes would be overwritten by merge"
I tried to change branches so that I might be able to push my changes and then merge them with the first branch, but I got this error:
"Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details."
I have no idea what to do, except possibly to email my changes to one of my friends and have them push my changes. However, I don't know what would happen with my local commits.
The problem is resolved. After making sure to sync all the commits I opened git bash and pulled the remote commits. After a few attempts I went back to Visual Studio and discovered that it had registered the merge. I resolved all of the conflicted files and was able to push the project.
Thanks to everyone who answered!
As dumb as it sounds, I just went to the command line, and it worked.
all worked fine.
If I did that same thing within Visual Studio, it didn't work. Go figure.
When using the Visual Studio Git Provider (VS 2013, VS2015), this situation can also arise in scenarios where a local Commit has been performed, but, when attempting to Pull from the server and merge, the error message:
"uncommitted changes would be overwritten by merge"
is still displayed, and the Pull action is cancelled.
This can occur because locally, there are Untracked Files that were not part of the local Commit, but are part of the remote Pull; the merge resolution cannot deal with this scenario.
Typically this occurs when some files such as T4 template outputs are included in a Commit on one workstation, but not on others.
Additionally, this can occur in Visual Studio 2015, when working with MVC6 projects (at time of writing), when files in the wwwroot folder have been included in a Commit on one workstation, but not on another (one possible cause of this is that the .gitignore files are different on the workstations attempting to work with the same server repository).
To resolve:
a) View the Team Explorer > Changes dialogue.
b) Verify that any Untracked Files that actually reside in the server branch are to be included in your Commits; to do this, right-click and select Add. Alternatively, if you intend them to be overwritten, you can select Delete. Please observe caution.
c) Perform a Commit, and then a Pull, and perform any merge conflict resolution that is required.
d) Perform a Push to update your Remote repository.
Right now you are trying to essentially do a git merge
with uncommited changes in your branch (pull is just fetch + merge). Git is rightfully complaining that such an operation would overwrite the uncommited changes in the branch.
To proceed with the pull operation you need to remove this uncommited changes from the working directory. There are a couple of ways to do this
If you are new to git I would probably start with option #1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With