Adding .gitignore file to the repository

From Matrix movie.

This is how looked my Changes view after I had built the code:

It’s because I didn’t add .gitignore file and with the first commit, .vs folder went to the repository.

According to the documentation:

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.

In the .vs folder are stored project specified files which shouldn’t go to the repository, but I committed them and they are already tracked by Git. Now I have to add a .gitignore file to the repository and remove those files from there to not be tracked any longer.

Adding .gitingnore file in Visual Studio

Under Ignore & Attribute Files in Repository Settings click Add Ignore File.

After that .gitignore with predefined content will appear.

Pretty simple, right? As you can see above .vs directory is one of the ignored directories/files defined in the .gitignore file.

Removing files from the repository

Now it’s time to remove previously committed files from the repository but not from the file system, by using a commandgit rm --cached -r

After this, I got rid of .vs directory and its content from the repository, and what’s more, it isn’t tracked any longer by Git.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *