Your daily Git workflow

Inspect differences

Compare working and staged changes before recording them.

8 minute lesson

~~~

git diff compares project states. The command you choose decides which states Git compares.

See working-tree changes that are not staged:

git diff

This compares the working tree with the index.

See the snapshot prepared for the next commit:

git diff --staged

This compares the index with HEAD.

To inspect everything changed since the current commit, including staged and unstaged work, use:

git diff HEAD

Untracked files do not appear in a normal diff because Git has no recorded version to compare. Find them with git status.

Review both ordinary and staged diffs before committing. This catches debug output, accidental edits, and changes staged from an older version of a file.

Exercise: stage one edit, make another edit in the same file, then run all three commands. Explain why each diff is different.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →