Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to add a file to gitignore on GitHub

Educative Answers Team

GitHub sees all files as either

  • tracked- files that have been previously staged or committed.
  • untracked - files that has not been staged or committed.
  • ignored - a file that Git has been explicitly told to ignore.

These ignored files are tracked in a .gitignore file that is at the root of the repository.

svg viewer

To add files to .gitignore:

  1. Create the file by using the command:
touch .gitignore
  1. Open the file and add the name of the file/folder you do not want to be tracked.

  2. If the file you are adding is already checked in, you will first need to untrack the file by using the command:

git rm --cached FILENAME

Ensure that the filename accurately matches the file you want to be ignored.

Configuring ignored files for all repositories

You can add a global .gitignore file that defines rules for adding files to ignore. This configuration can be done in the following way:

  1. Create a .gitignore_global file on the computer.
  2. Open Terminal.
  3. Configure git to use this file as .gitignore for all repositories by using the command:
git config --global core.excludesfile PATH

where PATH is the path to the .gitignore_gloabl file.


Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring