In the last movie we saw how we could use the .gitignore file to provide rules
to Git about what files ought to be ignored or not tracked.
In this movie I want to talk about to the kinds of files that you might want to
include in your .gitignore file. First, let's look at some general categories.
Compiled source code, the idea here is that you would want to store the
uncompiled code but at the compilation you would actually want to do after you pull down the repository.
The compiled code might depend on things like the processor that you're running
on your computer at the time, so you'd want to compile it fresh so that you would
make sure that it was compatible.
You would also want to ignore packages and compressed files, so that's files that
end in .zip, .gz, for example, it's also disk image files, those are typically
files that you're not using in the project itself.
For example, a zipped files is usually on its way somewhere else.
You're zipping it up so that you can download it or send it to someone, it's not
usable in itself, it has to be uncompressed before it's usable.
And you don't gain any advantage by having a compressed, Git does its own
compression, so you're not helping Git out by compressing those files.
The third one would be logs and databases.
The idea here is files that change often. So while we're working on our
project, it's logging information to a log file. We don't want every time you
hit get status, we don't want it to come up and tell us about those changes to the log file.
And then operating system generated files, these are files that have nothing
to do with our project, they are files that the operating system is using to keep track of things.
Maybe it's the window position on the desktop, or maybe it's things that are in the trash can.
We want to ignore those, we don't want to have those tracked in our repository
because they are really not about the project.
And the last general category would be user-uploaded assets.
Now this really applies mostly if you're talking about working with web projects.
Let's imagine for a moment that we have a PHP project, and we have a web form
where a user can upload an image.
Well, as we're developing and we're testing our code, we might try uploading
images, and we would tell our PHP code, hey, once you receive an image you have
to store it in this directory inside the project.
So it stores in that directory and then Git comes up and says, "Hey, I noticed
there is a new image file, do you want to add it to the repository?"
We don't, we want to ignore all those files, all the tests that we do,
everything is uploaded in those image directory's user-uploaded content, we
just want it to ignore.
That is dynamic and changing in the same way the log files and databases are changing.
Now those are some general categories, but I'd like to give you some more
specific ideas as well, and there are some great resources for this on GitHub.
So if you go on GitHub there's two URLs that you want to take a look at.
The first is a help article just about ignoring files that has some good tips in it.
And then the second is there is actually a github repository called gitignore
which has some great ideas in there as well.
Let's take a look at both of these.
So the first of these is the github help article about ignoring files, and it
has also some information just about ignoring files generally, including the
things that we just learned about gitignore.
But right here is what I want you to see: "Some good rules to add to this file
are:" and you can see they've broken out Compiled source, Packages, Logs and
databases, OS generated files.
So it gives you a list of some good and general ideas.
Now this is probably overkill for most people because you probably aren't going
to come across even half of these depending on what language you are using.
This is really a very general list.
To give more specific and look at your specific purposes, the gitignore
repository is a great place to look.
If we scan down here, you'll see that there is a list of all the different files
that are in here, these are files in the repository, and each one is a gitignore
file that's specific to a certain language.
So, for example, if you are working with Django, you can click on that, and you
can see here is the list of files that it thinks would be a good idea to ignore.
If we come over here, let's scroll down to another one.
Let's say that we're working Java, well here's a Java.gitignore file.
If we scroll down a little further here's one for Perl, let's click on that, and
now we see the list of files that typically would come up that you would want to
ignore if you are working on a Perl project.
Now it's not just the languages of the applications that you might be using,
there is also a folder here called Global, that has a lot of stuff about
operating systems or applications that you might be using.
So for example, if you are on OS X, here's a list of the files that are good to ignore for OS X.
If you're on Windows, then you can scroll down here, and here's a list of the ones
that are good to ignore on Windows.
So it's a great resource for you to comb through and figure out the components
that you might want to put in your gitignore file.
Of course, the other simpler way to do it is just to start creating your project,
and as files pop up that you want to ignore you can just take a second and add
those to the gitignore file.