Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effective Git

Effective Git

Michael Cordell

November 03, 2016
Tweet

More Decks by Michael Cordell

Other Decks in Programming

Transcript

  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. WHY

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

    is directly related to how it has been used in the past
  4. Commits in git are immutable Attempting to change: • Message

    • Content (file objects) • Parent commit results in the creation of a new commit
  5. IN PRACTICE: CONFIGURATION Learn to use aliases for faster git

    commands In your shell config: In your ~/.gitconfig $ git status $ g s
  6. IN PRACTICE: STAGING git add -p not git add .

    Use editor plugins for easy staging by hunk or line
  7. 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
  8. IN PRACTICE: BLAMING Use git blame to find why a

    line changed -w flag to ignore whitespace changes
  9. 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
  10. 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
  11. LOST A STASH? git fsck can be used to find

    files that were at one time staged or perhaps stashed and dropped
  12. End