Git Sitting In A Tree
An illustrated guide to Git.
Slide 2
Slide 2 text
Nothingness
git init
Slide 3
Slide 3 text
Nothingness
echo “Duck” > README.txt
README.txt
Slide 4
Slide 4 text
Tell git about our duck
git add README.txt
Staging Area README.txt
Duck
Slide 5
Slide 5 text
Save
git commit -m “I wrote ‘Duck’ into README.txt”
Staging Area README.txt
Duck
Commit
commit message
Slide 6
Slide 6 text
Save
git commit -m “I wrote ‘Donald Duck’ into README.txt”
Staging Area README.txt
Duck
Commit
Duck
Slide 7
Slide 7 text
Why not directly?
README.txt
Duck
Commit
Duck
Slide 8
Slide 8 text
Git hates us
README.txt
Duck
Commit
Duck
Slide 9
Slide 9 text
Git hates us
Git has opinions
Slide 10
Slide 10 text
“If you deny the Index [staging area],
you really deny git itself.” - Linus Torvalds
Slide 11
Slide 11 text
Reason
Splits your code into two sections:
Code that has been reviewed for a commit
Code that hasn’t
Slide 12
Slide 12 text
Reason
Splits your code into two sections:
Code in the staging area
Code not in the staging area
Slide 13
Slide 13 text
Example
I implemented both a new feature and a bug-fix and
forgot to commit them.
Slide 14
Slide 14 text
I’m happily coding
echo "bug-fix" >> README.txt
echo "new feature" >> README.txt
cat README.txt
duck
bug-fix
new feature
Slide 15
Slide 15 text
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
Slide 16
Slide 16 text
Seeing what’s left
git diff
@@ -1,2 +1,3 @@
duck
+bug-fix
new feature
Really, really useful
Slide 17
Slide 17 text
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
Slide 18
Slide 18 text
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
Slide 19
Slide 19 text
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
Slide 20
Slide 20 text
Take A Sip Of Coffee
Slide 21
Slide 21 text
Again
Slide 22
Slide 22 text
Staging Area/Index
We always commit by first adding or removing files to the
Index
Slide 23
Slide 23 text
git add
Adds files content to the staging area.
Staging Area README.txt
Duck
Slide 24
Slide 24 text
git add --patch
Adds some part (it will ask you) of the files to the staging
area.
Staging Area README.txt
new feature
Slide 25
Slide 25 text
git rm
Removes all the files content from the staging area.
Staging Area README.txt
Duck
Slide 26
Slide 26 text
git diff
Shows the difference between the staging area and the
working directory.
Staging Area README.txt
Diff
Slide 27
Slide 27 text
git commit -m “msg”
Commit file content in staging area with a
description/message
Staging Area README.txt
Commit
*
Slide 28
Slide 28 text
Good Work
Slide 29
Slide 29 text
Gotchas
Slide 30
Slide 30 text
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.
Slide 31
Slide 31 text
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.
Slide 32
Slide 32 text
And A Lie
Slide 33
Slide 33 text
Staging Area
What we call a staging area, Git officially calls
the Index.