About this chapter
This is the core loop you'll repeat every single day: see what changed, choose what to save, commit it with a clear message, and read back the history when you need to.
Lessons from courses
- 1 Checking status with git status Read git status output line by line: tell untracked, modified and staged files apart so you always know your Git repository's exact state.
- 2 Staging changes with git add Use git add and the staging area to stage specific files or run git add . - and control exactly what goes into your next Git commit.
- 3 Committing with git commit Run git commit and git commit -m to save staged changes. Learn what a commit really is: a snapshot with a message, author and parent link.
- 4 Committing only specific files Commit only chosen files in Git: stage named files, commit a path directly, or use git add -p to stage selected hunks within a single file.
- 5 Writing good commit messages Write clear Git commit messages: a concise imperative subject line, a body that explains why not what, and common conventions teams follow.
- 6 Viewing history with git log Read your Git history with git log and its most useful flags: --oneline, --graph, -p and -n to see commits the way you need them.
- 7 Seeing changes with git diff See exactly what changed in Git: git diff shows unstaged edits, git diff --staged shows what's ready to commit. Read the diff output line by line.
- 8 Ignoring files with .gitignore Use a .gitignore file to keep files out of Git: pattern syntax, per-project vs global ignore, and why it only affects untracked files, not tracked ones.
- 9 Moving and removing files Remove and move files in Git: git rm to delete, git rm --cached to untrack while keeping the file on disk, and git mv to rename or relocate.
- 10 Empty directories and .gitkeep Git ignores empty folders because it tracks files, not directories. Learn how to commit an empty directory with .gitkeep, plus .gitkeep vs .gitignore.