gitignore

Projected Time

About 30-45 minutes

Prerequisites

Here are links to lessons that should be completed before this lesson:

Motivation

Adding certain files to .gitignore will prevent staging and committing those files in git, protecting your private info like keys, passwords, and other secrets. It’s also useful to exclude very large or locally generated files from being saved unnecessarily.

Objectives

Participants will be able to:

Specific Things to Learn

Supplemental Materials

Lesson

Gitignore (Youtube video)
.gitignore (slides)

A basic .gitignore file Example
A basic .gitignore file Example

When you commit your project data to a version control site like GitHub or Bitbucket, unless you are paying for a private account, all of that data is publicly accessible to anyone.

Any private data should never accidently be committed or pushed to a git repo, and the best way to do that is by having git ignore them.

Examples of files often added to a .gitignore are:

Common Mistakes / Misconceptions

“I will just remember what not to commit.”

Guided Practice

  1. On your command line, navigate to your project’s root folder.

  2. Enter:

touch .gitignore
  1. Next, enter:
touch .my-secret-keys
git status

You should see both files as an untracked in git. Don’t add or commit anything yet, though.

  1. open .gitignore in your text editor:
code .gitignore
  1. add this text to your file:
# Project Secrets
.my-secret-keys
# Project-generated files
package-lock.json
# Locally-generated files
.DS_Store
  1. You should see the text of your ignored files darken or lighten in your IDE’s tree view.

  2. Go back you your command line and type:

git status

You should no longer see .my-secret-keys in your untracked files, because git is ignoring it!

Independent Practice

Check for Understanding

Form small groups and discuss: