Ignore all .log files with .gitignore

Description: Create debug.log, app.js and a folder build with a file inside. Make Git ignore all .log files and the build folder.

Hint:

  • Write the patterns *.log and build/ in a file named .gitignore.

Solution

Terminal output

$ mkdir ignore-demo
$ cd ignore-demo
$ git init -q
$ echo "log" > debug.log
$ echo "code" > app.js
$ mkdir build
$ echo "out" > build/out.js
$ printf "*.log\nbuild/\n" > .gitignore
$ git status -s
?? .gitignore
?? app.js
$ git check-ignore -v debug.log
.gitignore:1:*.log debug.log

How it works

  • Only .gitignore and app.js are shown. The log file and the build folder are hidden from Git.
  • git check-ignore -v tells which rule matched.

Read Git Ignore.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.