Brett Allred

be a student, not a follower

.gitignore – How to Re-index After Updating

When I am coding, a basic git workflow (if I am coding solo) looks like this:

git add .

git commit -am “Some Message”

git pull origin master

git push origin master

 

However, sometimes I forget to create a .gitignore file.  Without the .gitignore file, there are many files that get added that I don’t want tracked, and I don’t want clogging up my repository.  This mainly applies to resharper files but there are other files as well.  Here is one version of  .gitignore file that I use:

 

resharper.user
build/
[Bb]in/
[Oo]bj/
EFExtensions/EFExtensions.xml
.suo
.sln.cache
_ReSharper.
/
.user
.nupkg
.vs10x
.orig

 

This is all great but what happens if you have added all of the files to the git without having a git ignore file? You need to re-index in the following way:

git rm -r —cached .

git add .

git commit -am “Some message indicating what you did”

This removes all the files from the  git index then re adds them using the rules from the .gitignore file