6  Ignoring files with .gitignore

Learning Objectives

  1. Use a .gitignore file to stop Git from tracking files that do not belong in version control

What about pesky files that exist on our computer, that change sometimes but we don’t really actively use (e.g., .DS_Store, .ipynb_checkpoints, etc). We can tell Git to ignore such irrelevant files by creating and using a .gitignore file

6.1 Create a .gitignore file

Using the plain text editor of your choice, create a file called .gitignore inside the root of your Git repository. Inside the text file, list the files and folders you would like to ignore, one per line. For example:

.ipynb_checkpoints/
.DS_Store

Save the file, and add and commit it with Git. Next time you go to use version control, Git will not bother you about the files you listed there, even if they have changed!

6.2 .gitignore tips and tricks

  • append **/ to the beginning of any file/folder names listed in the .gitignore file to have them ignored in subdirectories within the repo as well
  • create a global .gitignore file so that you do not have to create the same .gitignore for all your homework repos