Slide 1

Slide 1 text

Everyday Effectiveness with git John Kary johnkary@ gmail.com @ johnkary Slides available at http://johnkary.net/talks Sunday, April 22, 2012

Slide 2

Slide 2 text

Intermediate ? • Version control? • git status, add, commit, log • git Immersion http://gitimmersion.com • Branching and merging • Maybe how git works internally • Getting git by Scott Chacon http://blip.tv/scott-chacon/git-talk-4113729 Sunday, April 22, 2012

Slide 3

Slide 3 text

Overview • Getting over the hurdle • Setting up your environment • Workflow Sunday, April 22, 2012

Slide 4

Slide 4 text

Part 1 Getting over the hurdle Source: http://www.flickr.com/photos/keokiseu/4620268471/ Sunday, April 22, 2012

Slide 5

Slide 5 text

git pre post Sunday, April 22, 2012

Slide 6

Slide 6 text

git Sunday, April 22, 2012

Slide 7

Slide 7 text

Chad Dickerson CEO @ Etsy RailsConf 2011 Keynote http://codeascraft.etsy.com/2011/06/06/optimizing-for-developer-happiness/ Optimize for developer happiness. “ ” Sunday, April 22, 2012

Slide 8

Slide 8 text

Excuses Sunday, April 22, 2012

Slide 9

Slide 9 text

I keep backups. Sunday, April 22, 2012

Slide 10

Slide 10 text

No, really, I keep backups. Sunday, April 22, 2012

Slide 11

Slide 11 text

Sunday, April 22, 2012

Slide 12

Slide 12 text

+ Automagically syncs + Cloud! + Distributed + Built-in versioning - Not searchable by contents - Not easy to experiment and roll-back - No diff-view between versions - No version metadata - Saved versions for only last 30 days Dropbox versioning is... Sunday, April 22, 2012

Slide 13

Slide 13 text

is Versioning NOT Version-Control Sunday, April 22, 2012

Slide 14

Slide 14 text

I’ve tried _____ Sunday, April 22, 2012

Slide 15

Slide 15 text

I’ve tried _____ Sunday, April 22, 2012

Slide 16

Slide 16 text

I’ve tried _____ Sunday, April 22, 2012

Slide 17

Slide 17 text

I’ve tried _____ Sunday, April 22, 2012

Slide 18

Slide 18 text

I’ve tried _____ Sunday, April 22, 2012

Slide 19

Slide 19 text

I’ve tried _____ it gets in the way of getting real work done Sunday, April 22, 2012

Slide 20

Slide 20 text

Photo: Photo by Jesse D. Garrabrant/NBAE via Getty Images The Truth Is... Learning git is an Investment It becomes second nature Accomplish More Work Faster Jump Higher Sunday, April 22, 2012

Slide 21

Slide 21 text

Has anyone picked up version control recently? Sunday, April 22, 2012

Slide 22

Slide 22 text

Part 2 Setting up your environment Source: http://www.flickr.com/photos/akahodag/3753216775/ Sunday, April 22, 2012

Slide 23

Slide 23 text

Installing git ~ $ brew install git ... ~ $ which git /usr/local/bin/git Homebrew The missing package manager for OS X http://mxcl.github.com/homebrew/ Sunday, April 22, 2012

Slide 24

Slide 24 text

Installing git ~ $ man git-log GIT-LOG(1) Git Manual GIT-LOG(1) NAME git-log - Show commit logs SYNOPSIS git log [] [..] [[--] ...] DESCRIPTION Shows the commit logs. The command takes options applicable to the git rev-list command to control what is shown and how, and options applicable to the git Easy man page access Sunday, April 22, 2012

Slide 25

Slide 25 text

Installing git ~ $ cat ~/.bash_profile source `brew --prefix git`/etc/bash_completion.d/git-completion.bash ~ $ source ~/.bash_profile ~ $ git sta stage stash status ~ $ git sta Bash command auto-completion Sunday, April 22, 2012

Slide 26

Slide 26 text

Interacting with your repository Sunday, April 22, 2012

Slide 27

Slide 27 text

For those already using git... Who is using a GUI? Sunday, April 22, 2012

Slide 28

Slide 28 text

For those already using git... Who is using a CLI? Sunday, April 22, 2012

Slide 29

Slide 29 text

git tower - http://www.git-tower.com Sunday, April 22, 2012

Slide 30

Slide 30 text

Gitbox - http://www.gitboxapp.com/ Sunday, April 22, 2012

Slide 31

Slide 31 text

github for mac - http://mac.github.com/ Sunday, April 22, 2012

Slide 32

Slide 32 text

Strongly STRONGLY encourage you to NOT use a GUI Sunday, April 22, 2012

Slide 33

Slide 33 text

git GUIs • Dumb-down underlying commands • Present limited command options • Not available on most remote servers • But there is one I recommend... Sunday, April 22, 2012

Slide 34

Slide 34 text

GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/ Sunday, April 22, 2012

Slide 35

Slide 35 text

GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/ (master) ~/Sites/mysite $ gitx Sunday, April 22, 2012

Slide 36

Slide 36 text

~ $ git config --global alias.lola "log --graph --decorate >> --pretty=oneline --abbrev-commit --all" (master) ~/Sites/mysite $ git lola git log-one-line --all (lola) Useful when on a remote sever Sunday, April 22, 2012

Slide 37

Slide 37 text

Customizing your shell Sunday, April 22, 2012

Slide 38

Slide 38 text

PS1 ~ $ cat ~/.bash_config source `brew --prefix git`/etc/bash_completion.d/git-completion.bash export PS1="\[\e[0;34m\]\$(__git_ps1) \[\e[0;31m\]\w \[\e[0m\]$ " (master) ~/Sites/mysite $ git checkout 9d9bc29 Note: checking out '9d9bc29'. You are in 'detached HEAD' state. You can look around, make experimental ... ((9d9bc29...)) ~/Sites/mysite $ Sunday, April 22, 2012

Slide 39

Slide 39 text

• gitflow - https://github.com/nvie/gitflow • git-extras - https://github.com/visionmedia/git-extras • git-legit - http://www.git-legit.org • Roll your own! Command aliases Sunday, April 22, 2012

Slide 40

Slide 40 text

Command aliases ~ $ cat ~/.bash_config alias g="git status" alias go="git checkout" alias ga="git add" alias gap="git add -p" alias gb="git branch" alias gca="git commit -v --amend" Shell Sunday, April 22, 2012

Slide 41

Slide 41 text

Command aliases (master) ~/Sites/mysite $ g # On branch master nothing to commit (working directory clean) alias g="git status" (master) ~/Sites/mysite $ go 9d9bc29 Note: checking out '9d9bc29'. You are in 'detached HEAD' state. You can look around, make experimental ... ((9d9bc29...)) ~/Sites/mysite $ alias go="git checkout" Sunday, April 22, 2012

Slide 42

Slide 42 text

Command aliases (master) ~/Sites/mysite $ g # On branch master # Untracked files: # (use "git add ..." to include in what will be committed) # # test.php nothing added to commit but untracked files present (use "git add" to track) (master) ~/Sites/mysite $ ga test.php (master) ~/Sites/mysite $ g # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # new file: test.php # alias ga="git add" Sunday, April 22, 2012

Slide 43

Slide 43 text

Command aliases (master) ~/Sites/mysite $ git commit -m "Add README" [master 05b8075] Add README 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README (master) ~/Sites/mysite $ gca 1 Updated README 2 3 # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # On branch master 6 # Changes to be committed: 7 # (use "git reset HEAD^1 ..." to unstage) 8 # 9 # new file: april21-2012.zip 10 # alias gca="git commit -v --amend" Sunday, April 22, 2012

Slide 44

Slide 44 text

Command aliases (master) ~/Sites/mysite $ gap diff --git a/README b/README index 7c39865..1056e9e 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ My Cool Project +Author: John Kary -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,s,e,?]? y alias gap="git add -p" Sunday, April 22, 2012

Slide 45

Slide 45 text

Command aliases Stage this hunk [y,n,q,a,d,/,s,e,?]? ? y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk nor any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk nor any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help alias gap="git add -p" Sunday, April 22, 2012

Slide 46

Slide 46 text

(master) ~/Sites/mysite $ gap diff --git a/README b/README index 7c39865..1056e9e 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ My Cool Project +Author: John Kary -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,s,e,?]? s Sunday, April 22, 2012

Slide 47

Slide 47 text

... Stage this hunk [y,n,q,a,d,/,s,e,?]? s Split into 2 hunks. @@ -1,2 +1,3 @@ My Cool Project +Author: John Kary Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y @@ -2,2 +3,2 @@ -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n (master) ~/Sites/mysite $ git status Sunday, April 22, 2012

Slide 48

Slide 48 text

... (master) ~/Sites/mysite $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: README # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: README # (master) ~/Sites/mysite $ git commit -m "Add author" Sunday, April 22, 2012

Slide 49

Slide 49 text

... (master) ~/Sites/mysite $ git lola * c7ccfcb (HEAD, master) Add README note * 9e35c29 Add author * 34501c6 Added first README Sunday, April 22, 2012

Slide 50

Slide 50 text

git aliases ~ $ git config --global alias.cp "cherry-pick" ~ $ cat ~/.gitconfig [alias] b = checkout -b bd = branch -d changelog = log --oneline --reverse cp = cherry-pick lol = log --graph --decorate --pretty=oneline --abbrev-commit lola = log --graph --decorate --pretty=oneline --abbrev-commit --all difffiles = diff --name-only unstage = reset HEAD Sunday, April 22, 2012

Slide 51

Slide 51 text

Part 3 Workflows Source: http://www.flickr.com/photos/antiuser/789307913/ Sunday, April 22, 2012

Slide 52

Slide 52 text

Sharing Models Sunday, April 22, 2012

Slide 53

Slide 53 text

Sharing Models Sole Developer John Sunday, April 22, 2012

Slide 54

Slide 54 text

Sharing Models Sole Developer with a remote server John Server Sunday, April 22, 2012

Slide 55

Slide 55 text

Sharing Models Fully Distributed John Chris Bill Sunday, April 22, 2012

Slide 56

Slide 56 text

Sharing Models Fully Distributed bananajour https://github.com/toolmantim/bananajour Sunday, April 22, 2012

Slide 57

Slide 57 text

Sharing Models Hybrid - Centrally Distributed John Chris Bill Central Server Sunday, April 22, 2012

Slide 58

Slide 58 text

Sharing Models Hybrid - Centrally Distributed Sunday, April 22, 2012

Slide 59

Slide 59 text

Sharing Models Sole Developer with a remote server John Server Sunday, April 22, 2012

Slide 60

Slide 60 text

Time for some live coding examples... Sunday, April 22, 2012

Slide 61

Slide 61 text

Resources John Kary johnkary@ gmail.com @ johnkary Online git tutorial - http://gitimmersion.com Getting git by Scott Chacon - http://blip.tv/scott-chacon/git-talk-4113729 Optimize for developer happiness - http://codeascraft.etsy.com/2011/06/06/optimizing-for-developer-happiness/ Homebrew - http://mxcl.github.com/homebrew/ git tower - http://www.git-tower.com/ Gitbox - http://www.gitboxapp.com/ github for mac - http://mac.github.com/ GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/ gitflow - https://github.com/nvie/gitflow git-extras - https://github.com/visionmedia/git-extras git-legit - http://www.git-legit.org bananajour - https://github.com/toolmantim/bananajour Live-coding repo - https://github.com/johnkary/everyday-git Slides - http://johnkary.net/talks Sunday, April 22, 2012