Skip to content

Instantly share code, notes, and snippets.

@chrisdaaz
Last active May 10, 2021 16:52
Show Gist options
  • Save chrisdaaz/e5491b2d8b231376783fa82eea4a5a81 to your computer and use it in GitHub Desktop.
Save chrisdaaz/e5491b2d8b231376783fa82eea4a5a81 to your computer and use it in GitHub Desktop.
A basic introduction to .gitignore for the "Git and GitHub for Librarians" course.

Gitignore

The .gitignore file is essential for keeping git repositories clear or any clutter.

This "Gitignore Explained" article from Free Code Camp does a great job of explaining the .gitignore file. Please read it.

Some common examples of files to include in your repository's .gitignore file are:

  • files containing sensitive server information (e.g. authentication keys, tracking codes, storage IDs, intranet URLs, etc.)
  • folders containing the output files for website applications / static site generators
  • files that are specific to your system or editor (e.g. DS_Store if you're on macOS)
  • files that git is not designed to track (i.e. proprietary, binary files): Microsoft Word / Excel / Access or Adobe PDF files. You can include these kinds of files in git repositories, but git won't tell you what --specifically-- is different between versions of those files, just that new versions of those files have been committed

While you can check-in and track Microsoft Word / Excel / Access or PDF files, sometimes it might not make sense to include these files in your Git repository, so these examples of proprietary files that Git can't track on a granular level might also be files you include in your .gitignore file.

The .gitignore file will allow you to keep all of your project files organized on your computer within the same folder, even if that folder is a git repository. For example, let's say you have a folder of PDFs you want to keep within your project-folder and that project-folder is a git repository. You could put all of your PDFs in a subfolder called "PDFs" and add that folder path to your .gitignore file so that those files never get pushed to GitHub. You're .gitignore file would include this line:

PDFs/

This was noted in the "Gitignore Explained" article, but it's worth repeating. Here's a list of .gitignore templates for a wide variety of code projects: https://github.com/github/gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment