Git

Add Git Ignore to an existing Visual Studio Solution (New Git Experience)

A few years ago I wrote a post covering how to Add Git Ignore to an existing Visual Studio Project which was using Visual Studio 2015 I believe. Though it is an old post, it holds up through the current version of Visual Studio. Fast forward to today and Visual Studio has a new Git Experience in preview which alters this process. This post will cover adding a Git ignore file to an existing solution using Visual Studio’s new Git experience. If you don’t see the Git menu in Visual Studio see the previous link for information on enabling the feature preview.

Using Visual Studio to add a .gitignore

Open Visual Studio and the solution needing an ignore file. From the top menu select Git > Settings.

The above will open Visual Studio’s Options with Source Control > Git Global Settings selected. From the list on the left select Git Repository Settings and then click the Add button for Ignore file.

The above will add a .gitignore file with all the proper files ignored for a typical Visual Studio setup. Switch to the Git Changes window and enter a commit message and then click the Commit Staged button to commit the change to your current working branch.

Stop tracking files that should be ignored

To stop tracking the files in the ignore file open a command prompt and navigate to the directory that contains your solution file (.sln) and run the following commands.

git rm -r --cached . 
git add .
git commit -am "Remove ignored files"

The Git commands above were pulled from here. There are other answers in that thread if the above doesn’t work on your project for some reason.

Wrapping Up

It is always simpler if you can start a project with a Git ignore file in place, but if for whatever reason that couldn’t happen hopefully this post will get you going. If you aren’t using the new Visual Studio Git experience then the original version of this post will be more helpful. Check out the Microsoft post for more details on the new Git experience.

Add Git Ignore to an existing Visual Studio Solution (New Git Experience) Read More »

Visual Studio 2017 error encountered while cloning the remote Git repository

Going through the process of getting Visual Studio 2017 installed on all my machines has been pretty smooth. The new installer works great and makes it much clearer what needs to be installed.

The issue

The one issue I have had, which was only an issue on one install, is an error when trying to clone a repo from GitHub. I say GitHub but really it would be a problem with any Git repo. The following is the error I was getting.

Error encountered while cloning the remote repository: Git failed with a fatal error.
CloneCommand.ExecuteClone

The solution

After searching I found a lot of things to try. I uninstalled and reinstalled Git for Windows multiple times using both the Visual Studio Installer and the stand alone installer. I finally stumbled onto this forum thread which had a solution that worked for me. The following is a quote of the reason for the issue and a fix posted by J Wyman who is a software engineer for Microsoft’s Developer Division.

After intensive investigation we were able to determine that Git was accidentally loading an incorrect version of libeay32.dll and ssleay32.dll due to library loading search order and precedence rules. Multiple users have confirmed that copying the binaries from the “<VS_INSTALL>\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin\” folder to the “<VS_INSTALL>\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\libexec\git-core\” folder completely resolved the issue for him.

Any other users seeing similar problem should attempt the same solution.

I hope this gets other people up and running as it did me. My only worry about this fix is what happens with Git gets updated.

Visual Studio 2017 error encountered while cloning the remote Git repository Read More »

Visual Studio 2015 Team Explorer Fails to Undo Changes Using Git

At times I will make some quick changes to a project in Visual Studio to try something out knowing that I will undo the changes when done. Most of the time this works great with no problems, but a few times I am unable to get Visual Studio to undo the changes. Fist I am going to review the steps I normally use to undo and then I will cover the steps I use when files refuse to be undone. Just to be clear I am using Git base source control.

Normal undo changes

Normally when I am ready to undo a set of changes I open the Team Explorer window and select Changes from the drop down at the top of the window. Next I right click on the file, files, or directory I want to undo changes on and click Undo Changes.

undochanges

This show a message box asking for confirmation before undoing the changes. Click Yes to undo the changes.

undochangesyesnomessagebox

If all goes well the select files and/or directory will have reverted and no longer have any changes.

Undo failed now what?

If you undo didn’t clear the changes as expected now what? Well the best answer I have found is to open a command prompt and navigating to the directory that contains the file that needs to be undone and then run the following command. In this example the changes to gulpfile.babel.js  will be undone. This will work for both added and changed files.

git checkout gulpfile.babel.js

If you want to undo all the changes in a branch it takes a couple of commands. This first command will remove all changes to tracked files including staged files.

git reset --hard

Next if you have any files that were added (or not already tracked by Git) the following command will remove them.

git clean -f

Your repo will be back to its starting state as if it had just been cloned.

Caution

When using the above commands be careful as any changes will be gone and Git will have no record of them. For added files the file will be removed and again Git will have no record of the file. This mean these operations are permanent and should be used with a great deal of caution.

Visual Studio 2015 Team Explorer Fails to Undo Changes Using Git Read More »

Add Git Ignore to existing Visual Studio Project

Last week I mentioned adding a .gitignore file to keep a configuration file from causing issues across machines. Visual Studio make it super easy to add, but the next time I made a change to the project the configuration file showed up in my changes again. Turns out that if Git is already tracking a file adding it to the ignore file will not do anything. I am going to walk through adding an ignore file and then cover the one of the processes that can be used to stop Git from tracking files that are in your ignore file.

Using Visual Studio to add a .gitignore file

Inside of Visual Studio open the Team Explorer window. If you don’t already have it open use the quick launch in the upper right hand side of the window to search for it. If it is not already on the Home page click the house icon in the top of the Team Explorer window.

TeamExplorerHome

Click the settings option.

TeamExplorerSettings

Then click Repository Settings.

TeamExplorerRepositorySettings

Now click the add link next to the Ignore File description. This will add the .gitignore file will all the defaults set for things that should be ignored. You could add the file manually, but then you would not get the nice set of default values. If you do decide to add the file manually this repo contains all the defaults that should be ignored for a project using .NET/Visual Studio.

Now that the file exists check it in.

Stop tracking files that should be ignored

To stop tracking the files in the ignore file open a command prompt and navigate to the directory that contains your solution file (.sln) and run the following commands.

git rm -r --cached . 
git add .
git commit -am "Remove ignored files"

That seemed to do the trick for me. The git commands I found here. If you click on that link you will see there are lots of options on which commands to use for this process. If the above doesn’t work for you one of the other answers should meet your needs.

In the future I will be making sure my ignore file exists first just to avoid any issues.

Add Git Ignore to existing Visual Studio Project Read More »