World map

 

BM: Baca dalam Bahasa Melayu

World 1: Save Points

Ignore files

You will learn: how to tell Git which files to never save.

The problem

Four items wobble in the working folder: index.html, debug.log, .env and node_modules/. Three of them are junk or secret.

Your folder fills up with junk: logs, downloads, even .env with your passwords. One careless git add . grabs it all.

Watch

Before: git status -s lists debug.log and error.log. After writing *.log into .gitignore, only .gitignore is listed. Terminal output: $ git status -s ?? debug.log ?? error.log $ echo "*.log" > .gitignore $ git status -s ?? .gitignore

A .gitignore file lists names Git should skip. One line, *.log, and both log files vanish from git status.

Watch

Three echo commands build a .gitignore. cat shows its three lines: node_modules/, .env and *.log. Terminal output: $ echo "node_modules/" > .gitignore $ echo ".env" >> .gitignore $ echo "*.log" >> .gitignore $ cat .gitignore node_modules/ .env *.log

Each line is a pattern. A name ending in / means a folder. * means “anything”. > writes a new file, >> adds a line.

Try it

Should Git ignore it, or keep it? Sort each file.

Drag a card into a box. Or tap the card, then tap the box.

      Try it

      Hide the log files from Git. Then put .gitignore in the box.

      Working folder
      Staging area
      • Empty
      Repository
      • 3 save points
      • Add purple style
      • Add home page
      • Add README

      Check

      You committed debug.log last week. Today you add *.log to .gitignore. What happens to debug.log?

      Pick one answer.

      You did it!

      You can now keep junk and secrets out of your commits.

      Go deeper (optional)

      Commit your .gitignore, so your whole team uses it. A line starting with ! brings a file back, like !keep.log. git add . skips ignored files without a word.

      With *.log in .gitignore, git add . adds only .gitignore. The two log files stay out. Terminal output: $ git add . $ git status -s A .gitignore