Git Beyond Push & Pull - Jørgen Kvalsvik - NDC Oslo 2024

Learn essential Git practices beyond basic commands: commit hygiene, staging strategies, rebasing workflows, and debugging techniques. Master tools like bisect and cherry-pick.

Key takeaways
  • Git’s staging area (index/cache) provides fine-grained control over changes - use git add -p for interactive staging of specific hunks within files

  • Write focused, single-purpose commits that do one logical change. This makes them easier to review, cherry-pick, and understand later

  • Follow the 50/72 rule for commit messages:

    • 50 character limit for the subject line
    • 72 character limit for the message body
    • Write subjects in imperative mood
  • Commit messages should explain the WHY behind changes, not just WHAT changed. The code already shows what changed, but the motivation and reasoning needs to be documented

  • git bisect is a powerful debugging tool that works best when:

    • Each commit builds and passes tests
    • Commits are focused and well-documented
    • Changes can be tested with a clear yes/no outcome
  • git rebase can be used to:

    • Clean up commit history before pushing
    • Reorganize commits into logical groups
    • Fix up earlier commits with --fixup and --autosquash
  • Public history should be treated as immutable, but local history can and should be rewritten to create clean, logical commits

  • Use git cherry-pick to selectively apply changes from one branch to another

  • Higher resolution tools like patch mode (-p) provide more control than file-level operations

  • Regular committing with good hygiene practices makes Git’s advanced features more useful and powerful later