Git in Everyday Life

Go git ya' some

What will I Cover?

  • All 159 git sub-commands
     
  • All possible git workflows
     
  • Best practices

Git Subcommands

  • init, clone, status, diff, add, commit, log, blame, branch, tag, fetch, pull, push, merge
    • Not going to talk about these

Git Subcommands (cont)

  • remote, rebase, revert
    • Not going to talk about these either

Git Subcommands (Cont)

  • checkout, reset, mv
    • I might talk about these

Git Checkout

  • There's more to it that just checking out a branch/tag.
  • If you want to cleanly undo changes to a file:

    git checkout -- <path-to-file>

Git Reset

  • Another undo; this time, wipe out all changes in the working tree:

    git reset --hard HEAD

Git Mv

  • Like Posix mv, rename or move a file. Difference? Git will be able to track the change.
     
  • If you use the Posix mv, git may see the change as a deleted file and a new file. Sometimes it can work it out and sometimes it can't. Use git mv.

    Please.

Git Workflows

  • Clone a repository
  • Change the code
  • Commit the changes
  • Push the commit
  • Party

    Dude

Git Workflows (CONT)

  • Clone a repository
  • Make a change
  • Commit your changes
  • Attempt to push to the repository (fail)
  • Pull current from repository
  • Fix all conflicts
  • Commit fixed conflicts
  • Attempt to push to the repository (fail)
  • Pull current from repository
  • Fix new conflicts
  • Commit fixed conflicts
  • Attempt to push to the repository (fail)
     
  • Quiz: what happens next?

Git Workflows (Cont)

  • Fork repository (or clone repository)
  • Create a branch
  • Make changes
  • Commit the changes
  • Push the changes to your branch repository
  • Submit a pull request
  • Enjoy the sound of crickets
  • If receive notice that pull request was accepted:
    • Rejoice
  • Else
    • Mutter incoherently and try again (or not)

Best Practices

  • Commit === related changes
    • Small commits === goodness
    • Frequent commits === goodness
    • Half-done commits === badness
      • Consider stash
    • Test before commit === goodness
      • 3 commits to fix earlier commits === badness
    • Proper commit messages === goodness
      • Summary (<=50 chars) + Longer description if necessary
  • Git is not a backup system
    • If you need a backup system, get a backup system

Best Practices (More)

  • Branches === Goodness/Badness
    • Long-lived branches === Badness
      • Or at least Uncomfortableness
    • Feature branches === Goodness

  • Be mindful of your surroundings
    • If you are contemplating an earth-shattering change in an area you KNOW others are working in, stop, communicate and perhaps defer the change to a later date.
      • 50,000 merge-conflict related assaults could have been avoided in America last year if there had been just a little bit of communication.

Best Practices (again)

  • Git is like a playground: if you don't agree on the workflow (rules) up front, you're going to have hair-pulling and general unpleasantness.
    • A trip to the principal's office won't fix this - you must have well-defined rules.

Git in Everyday Life

By naiveroboticist

Git in Everyday Life

A rundown of some useful git commands and git workflows.

  • 440