user1102550 user1102550 - 19 days ago 8x
Git Question

Git clone causing lots nuget errors - suspect I'm committing too much

I have a .NET solution with about 10 projects of various things, MVC, libs and console app. We're in the process of using it with Git for the first time - BitBucket and SourceTree. Works fine on my local machine but when I do a clone, to test whether it's working properly I get loads of Nuget error, missing references and updating packages gets errors about the package already existing. It's a mess. My "solution" was to delete the whole packages folder and reinstall which works, sort of, but isn't a proper solution. So my question is as someone new to Git, not brilliant with Nuget, is where is it likely I'm going wrong in the commit process.

I suspect that I'm not excluding files properly - the project on Bitbucket is huge at 1GB. I thought the

by default excluded the key build files but I am a little unsure what files it is best practice to ignore so I can look at the
and see what actually is getting pushed to Bitbucket.

The missing references, what is happening there? Could there be copy local issues with DLLs?

Any help would be appreciated. Hope the question isn't too vague? In some ways a slightly higher level take on what I should be doing would be just a helpful as specific technical points.


This is the relevant section that I currently have in my .gitignore:

# NuGet Packages
# The packages folder can be ignored because of Package Restore
# except build/, which is used as an MSBuild target.
# Uncomment if necessary however generally it will be regenerated when needed

(I believe this .gitignore was generated by Visual Studio.)

The important part is to ignore the packages folder, but commit the packages.config file for each project. Then you can use the Restore Nuget packages menu option in Visual Studio to install packages as needed.

If you have accidentally committed the packages folder, then to clean up your current repo you can do:

git rm --cached packages/*
git commit -m "Remove Nuget packages from repo"

Then as long as you've added the packages folder to the .gitignore file, you should be good to go.