Effective Git

Effective Git


Michael Cordell

November 03, 2016


  1. 1.

    If that doesn't fix it, git.txt contains the phone number

    of a friend of mine who understands git. Just wait through a few minutes of 'It's really pretty simple, just think of branches as...' and eventually you'll learn the commands that will fix everything.
  2. 14.


  3. 17.

    Since git deals with history, git’s effectiveness as a tool

    is directly related to how it has been used in the past
  4. 20.
  5. 21.
  6. 30.

    Commits in git are immutable Attempting to change: • Message

    • Content (file objects) • Parent commit results in the creation of a new commit
  7. 33.

    IN PRACTICE: CONFIGURATION Learn to use aliases for faster git

    commands In your shell config: In your ~/.gitconfig $ git status $ g s
  8. 34.
  9. 35.
  10. 36.

    IN PRACTICE: STAGING git add -p not git add .

    Use editor plugins for easy staging by hunk or line
  11. 37.
  12. 38.
  13. 39.

    IN PRACTICE: COMMITTING First line is capitalized, short (50 chars

    or less) summary Second line is blank Rest of commit message should explain why and other useful information about the change See Tim Pope’s blog post on commit messages
  14. 53.
  15. 57.
  16. 58.
  17. 59.

    IN PRACTICE: BLAMING Use git blame to find why a

    line changed -w flag to ignore whitespace changes
  18. 60.
  19. 61.
  20. 62.
  21. 82.

    FIXING A BAD MERGE Usually this is as simple as

    backing the commit out by reseting one commit back git reset --hard HEAD~1 If you want to just fix a single badly merged file checkout the file you want git checkout GOOD_REF -- file
  22. 83.

    REFLOG FOR EVERYTHING ELSE git reflog keeps a reference of

    reach change in the HEAD reference (checkouts, rebase, cherry-picks, etc.) find the commit from before the change you want to fix and reset/checkout against it reflog expires after 90 days, but you can turn this off and have it never expire
  23. 84.
  24. 85.
  25. 86.
  26. 88.

    LOST A STASH? git fsck can be used to find

    files that were at one time staged or perhaps stashed and dropped
  27. 89.
  28. 96.