~/hackweb.dev
Staging and Committing
Quiz
...

Staging and Committing

beginner · updated Tue Sep 08 2026Contribute

Stage changes with git add and save snapshots with git commit.

Staging and Committing

Git uses a three-step process to save changes: working directory → staging area → repository.

The Three Areas

  1. Working directory: Files you edit directly
  2. Staging area: Changes marked for the next commit
  3. Repository: Permanent history of commits
Working Directory → git add → Staging Area → git commit → Repository

Staging Changes

Add specific files:

git add file.txt

Add all changes:

git add .

Committing Changes

Save staged changes with a message:

git commit -m "Add login page"

Good Commit Messages

  • Use the imperative mood (“Add feature” not “Added feature”)
  • Keep under 72 characters
  • Explain what changed and why
  • Reference issue numbers when relevant

Best Practices

  • Commit early and often
  • Don’t stage and commit unrelated changes
  • Write meaningful commit messages
  • Review changes before committing with git diff

Common Mistakes

  • Committing all changes without staging first
  • Using vague messages like “fix” or “update”
  • Committing large files or sensitive data
  • Forgetting to add files before committing