GIT · Foundations · 8 min

Leave generated files behind

Add useful ignore rules without hiding ordinary source files.

Not completed

Your task

Create and commit .gitignore so build/output.txt and debug.log are ignored. Keep those files on disk and app.txt tracked. An ordinary notes.txt file must not be ignored.

What you’re aiming for

  • .gitignore is committed.
  • Build output and logs are ignored but still exist locally.
  • Generated files are not tracked; normal text files remain eligible.

1. Prepare your practice folder

Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-git-ignore-build-output && cd opsrung-git-ignore-build-output

Run these setup commands in that folder:

SETUP — RUN ONCE
git init --initial-branch=main
git config --local user.name 'Practice Learner'
git config --local user.email 'practice@example.invalid'
printf 'Source stays tracked.\n' > app.txt
git add app.txt
git commit -m 'Initial source'
mkdir build
printf 'Generated fixture output.\n' > build/output.txt
printf 'Synthetic debug output.\n' > debug.log
Only if your personal Git settings interfere

You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.

OPTIONAL REPOSITORY OVERRIDES
git config --local commit.gpgsign false
git config --local core.autocrlf false
git config --local core.hooksPath .git/practice-no-hooks

Retry the failed command afterward. These settings apply only inside this practice repository.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

An ignore rule does not remove an already tracked file. These generated files start untracked.

Hint 2

Use one rule for the build directory and one for .log files.

Hint 3

Put build/ and *.log on separate lines, then commit only .gitignore.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
git status --ignored
git ls-files
git check-ignore build/output.txt debug.log
git log --oneline

What you should see

  • git ls-files lists .gitignore and app.txt, without build/output.txt or debug.log.
  • git check-ignore prints build/output.txt and debug.log.
  • git status --ignored shows the generated files as ignored and the working tree is otherwise clean.

If your result differs: Keep the generated files on disk. An ignore rule of * is too broad: ordinary files such as notes.txt should still be eligible for tracking.

Compare with one possible solution

Edit .gitignore to contain:

build/
*.log
ONE POSSIBLE SOLUTION
git add -- .gitignore
git commit -m "Ignore generated output"

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.