Ignore or include only specific folders/files in a git repository

The following example shows how you can include only some files or directories from a working git repository and exclude all the others. You can simply add these lines into the .gitignore file of the project.

Source: stackoverflow.com. Who else?