CHAPTER 6 · 1 lesson · 13 exercises
Stashing and .gitignore
Temporarily shelve uncommitted work with git stash, and ignore untracked files with .gitignore.
This chapter covers handling changes you do not want to commit right now.
1. Stashing in-progress work:
You are in the middle of a feature when an urgent bug fix comes in. Switching branches with dirty files can be blocked by Git. Use git stash to safely shelve uncommitted changes. Your working tree becomes clean, you can switch branches, and when you return, run git stash pop to restore your work.
2. Files you never want in Git:
Secret API keys, environment files, build outputs, OS temporary files. If untracked files clutter git status, you might accidentally push credentials with git add .. Adding patterns to .gitignore tells Git to ignore them completely.
Remember the golden rule of .gitignore: Files already committed cannot be ignored simply by adding them to .gitignore later. Always write .gitignore first before creating files.
Lessons in this chapter
stash and .gitignore
- 06Stashing and ignoring changes (stash / .gitignore)Use git stash to temporarily shelve and restore uncommitted changes, and use .gitignore to exclude untracked files from version control.Go to the exercises