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

Git In A Tree

Git In A Tree

An illustrated guide to Git

0622623d54d869a4ac51efc074d501df?s=128

Daniel Öberg

November 13, 2011
Tweet

Transcript

  1. Git Sitting In A Tree An illustrated guide to Git.

  2. Nothingness git init

  3. Nothingness echo “Duck” > README.txt README.txt

  4. Tell git about our duck git add README.txt Staging Area

    README.txt Duck
  5. Save git commit -m “I wrote ‘Duck’ into README.txt” Staging

    Area README.txt Duck Commit commit message
  6. Save git commit -m “I wrote ‘Donald Duck’ into README.txt”

    Staging Area README.txt Duck Commit Duck
  7. Why not directly? README.txt Duck Commit Duck

  8. Git hates us README.txt Duck Commit Duck

  9. Git hates us Git has opinions

  10. “If you deny the Index [staging area], you really deny

    git itself.” - Linus Torvalds
  11. Reason Splits your code into two sections: Code that has

    been reviewed for a commit Code that hasn’t
  12. Reason Splits your code into two sections: Code in the

    staging area Code not in the staging area
  13. Example I implemented both a new feature and a bug-fix

    and forgot to commit them.
  14. I’m happily coding echo "bug-fix" >> README.txt echo "new feature"

    >> README.txt cat README.txt duck bug-fix new feature
  15. Committing the feature only git add --patched README.txt && git

    commit -m “Feature added” Staging Area README.txt new feature Commit Duck new feature new feature
  16. Seeing what’s left git diff @@ -1,2 +1,3 @@ duck

    +bug-fix new feature Really, really useful
  17. Committing that git add README.txt && git commit -m “Bug

    squashed” Staging Area README.txt bug-fix Commit Duck new feature bug-fix bug-fix
  18. Send Specific Patch Now I can freely choose to send

    a patch that contains only the bug-fix to my boss (he can have the new feature on his birthday). Duck new feature bug-fix
  19. Remove Specific Patch ‘New feature’ might have contained a serious

    bug. I can the remove the new feature without touching the bug-fix. Amazing, you say. Duck new feature bug-fix
  20. Take A Sip Of Coffee

  21. Again

  22. Staging Area/Index We always commit by first adding or removing

    files to the Index
  23. git add Adds files content to the staging area. Staging

    Area README.txt Duck
  24. git add --patch Adds some part (it will ask you)

    of the files to the staging area. Staging Area README.txt new feature
  25. git rm Removes all the files content from the staging

    area. Staging Area README.txt Duck
  26. git diff Shows the difference between the staging area and

    the working directory. Staging Area README.txt Diff
  27. git commit -m “msg” Commit file content in staging area

    with a description/message Staging Area README.txt Commit *
  28. Good Work

  29. Gotchas

  30. git add Git has a list of files. By running

    git add you also append the filenames given to this list. Nasty, nasty, nasty. Lots of confusion from this feature.
  31. git commit -a This is the reason for tracking the

    files. By adding an -a you tell git to add all its tracked files file contents to the staging area and then commit it all.
  32. And A Lie

  33. Staging Area What we call a staging area, Git officially

    calls the Index.
  34. Thanks for listening

  35. United Lambdas Daniel Öberg daniel@unitedlambdas.com