develop with

Ignore file in Git

Excluding files from a git repo

Ignore file in Git

Sometimes as you are developing your project there are temporary files or data directories you want to exclude from git. Ignoring these files help to prevent the data from being checked into the repository by accident.

To ignore files, you’ll need to add a file to your folder called .gitignore which will specify a set of rules on what to exclude. This file needs to be added to git git add .gitignore and committed to your repository.

A .gitignore file supports regex and uses # as a delimiter for comments within the file.

Example gitignore file:

# exclude log files
*.log
**/*.log

If file was added to git, you will need to remove the file being tracked by git.

Example of untracking a file and keep it in your folder:

git rm --cached filename

For a more comprehensive description of how to ignore files, take a look at github’s ignorefiles page.

comments powered by Disqus

Want to see a topic covered? create a suggestion

Get more developer references and books in the developwith store.