Your daily Git workflow

Ignore generated and private files

Use .gitignore for files that should not enter the repository.

8 minute lesson

~~~

Some files belong in your working tree but not in project history. Examples include generated output, local settings, dependencies, and secret files.

Create a .gitignore file and list patterns:

node_modules/
.env
dist/

Check the result:

git status

Matching untracked files should disappear from the status output.

Ignore rules affect untracked files. If .env is already tracked, adding it to .gitignore does not remove it from the index or earlier commits.

You can inspect which rule matches a path:

git check-ignore -v .env

Be careful with secrets. Ignoring a file prevents a future accidental git add, but it cannot revoke a credential already committed. Rotate an exposed secret first, then clean up the repository history if necessary.

Commit the .gitignore file when the rules apply to everyone on the project. Use repository-local excludes for personal files that should not become shared policy.

Exercise: ignore notes.local, verify the matching rule, then confirm that git add notes.local refuses to stage it unless you explicitly force the operation.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →