Last Updated: 08/16/2010 09:13:00 PM

GIT: Giving files the cold shoulder .gitIgnore

GIT: Giving files the cold shoulder .gitIgnore

Much like celebrity gossip, there are some things you just don't care about keeping up with.  For those files that you have no desire to keep track of you will need to modify your .gitIgnore file.

At the git bash command line type this:

$ cat .gitignore

For me, I get the following results that show me what files are on the "naughty" list:

So everything under the WEB-INF folder is ignored as well as the litepost folder, also any file ending in .project and any file named settings.xml are ignored by GIT. Git sees these files and says "You broke my heart! You are dead to me!"  Ok, that is a bit melodramatic, but you get the point.  GIT doesn't care what goes on with these files.  What happens in the WEB-INF folder, STAYS in the WEB-INF folder.

However I noticed on my computer when I edited a file using notepad or notepad++ a file a mysterious file with a .swp extension would show up. For instance in my FW1 folder that I pulled down from github to play with (Sean Corfield you are a genius) I edited his README.txt file using notepad.

Then I ran the: 

$ git status

command .  This is what returns: 

See that .README.swp file? What the heck is that?  After using my google-fu skills I found that these are swap files created by windows.  I really don't want to version control these files, so I need to tell GIT to "just say no" to .swp files. It is dead to me!  I don't care what Windows does in the background, Honestly,  I just want to add more documentation to Sean Corfield's one file framework. Speaking of Sean doesn't this older pic of him look like he should be in an Irish rock band?

   That is him right?

Back on topic.  I want to ignore .swp files. The books I read told me to modify my .gitIgnore file.  Ok here is were the "For Dummies" part comes in. I could not find that file.  I looked. Honest. The book I was reading made it seem like it should be apparent how to change the file. Put the dunce cap on me, I couldn't find the file much less change it.  Using more google-fu  I found it is actually in the root folder you are working on. In my example where I pulled down Sean Corfields FW1 from GitHub (See my other article on how to do that.) I looked in C:\User\Username\FW1 and this is what I saw:

OK . . . I actually didn't see the big yellow arrow, I drew that to help out.  I opened that file and saw this:

Hey! That is the same thing from the cat .gitIgnore command!  Cool, I may have found it! Lets add *.swp to file and save, maybe we will get lucky!

Now change the readme file, lets add "Sean Rocks!"

Now lets run the command to see the status of our git controlled files and see if any .swp files show up.

$ git status

This is what I get:

Look at that ! No more .swp files!  Ok maybe the books thought this was easy, but I am just glad to figure this out. I am a dummy remember?