I am having difficulty in doing a pull from origin
. I keep getting:
"Cannot pull because there are uncommitted changes. Commit or undo your changes before pulling again. See the Output window for details."
This also applies to switching branches. I get a similar sort of message, but this does not always happen.
I am using Visual Studio 2015 Update 1 and Visual Studio Team Services Git. On my machine I have a local master
branch, and development branches. Every time I switch to master
and then I do a pull I get the error message. I have resorted to doing a stash and drop stash (command line) and sometimes I use TortoiseGit to do the pull and it works.
What is strange is even if I try to revert (on the uncommitted files) using TortoiseGit it shows that it was reverted successfully (I have already tried Visual Studio undo, nothing happens). Trying to pull again, it is still the same problem. The uncommitted files will be there and sometimes when I do a git status
it says there is nothing to commit.
Just a note: This can happen even after switching from a branch onto master
. In this case there is no way there can be uncommitted changes, because I would not have been able to switch in the first place.
I am still new to Git, but I would like to know if there is a better way of solving this as I would like to use one environment instead of using switching between different environments for each task; it's easier for me to just do everything from Visual Studio. I have already read up on:
TFS/GIT in VS Cannot switch to master because there are uncommitted changes
UPDATE
It seems like this problem has to do with line endings.
By doing a git diff -R
you can see that a line ending has been added, "^M", and it is different. Removing the * text=auto
in gitattributes (then check for changes) and putting it back on again so that the gitattributes does not signal a change of itself that needs to be committed seems to help, there will not be any changes.
I had this issue in Visual Studio 2017 build 15.5 and what fixed it for me was going into Team Explorer Settings → Global Settings and setting "Prune remote branches during fetch" and "Rebase local branch when pulling" to True.
http://www.codewrecks.com/blog/index.php/2017/12/23/configure-visual-studio-2017-15-5-for-pull-rebase/
Also MS has the Instructions here: https://docs.microsoft.com/en-us/azure/devops/repos/git/git-config?tabs=visual-studio&view=vsts#prune-remote-branches-during-fetch The facepalm moment is when you realize that "We recommend setting this option to True at the global level." is not the default setting on those items.
This happens sometimes even with me. If you are using Visual Studio, there is an easy way to make your way clear.
For Visual Studio 2013 and above, follow the following instructions as this worked for me:
git reset
and hit EnterThat's it. Git will be reset and then you will be able to pull your request easily.
VS2015: Tools > Nuget Package Manager > Package manager console. Worked like a charm. Thanks.
For me, this issue was caused by having two files, "Web.Config" and "web.config". I guess this is ok in Linux/Unix but Windows can only store one of them locally. I detected this in azure devops exploring the files. I deleted one of them and problem was solved. I guess this problem could be caused by any file.
In
Visual Studio
openOutput Window
and switchShow output from
toSource Control - git
,git
will let you know about what stops it from pulling. One of the most common causes can be of course something like this:It simply means that 44 files have been added to the
remote
repository which are not part of thelocal
repository. OpenGit Bash
and run this command:This may solve the problem or end up to a an error like this:
If you are sure about adding them to the
local
repro, just add them usinggit add * -f
or remove mistakenly added files fromremote
.Hope this helps.
Type
git status
into a command line opened at that directory. If there is red and/or green text, you have changed some stuff and not added and committed. Either revert the files (by doinggit checkout -- <file>
), or add and commit (by doinggit add --all
thengit commit -m "commit message"
). You can then check out branches or whatever else you want to do.Try with these commands by going to the working directory of the project in the command prompt.