$30 off During Our Annual Pro Sale. View Details »

Git In It: Beginning to Use Git

Git In It: Beginning to Use Git

Covers common misconceptions about version control, how to setup your environment to work with git, how to get up and going with git in your daily development workflow, and where to learn more.

Video: http://vimeo.com/johnkary/git-in-it-drupalkc

Presented at Kansas City Drupal User Group
June 26, 2012

By John Kary
http://twitter.com/johnkary
johnkary at gmail

http://meetup.com/Greater-Kansas-City-Drupal-User-Group/events/66995032/
Thanks to VML for the meeting space!

Sorry for the presenter's view, recorded the wrong screen.

John Kary

June 26, 2012
Tweet

More Decks by John Kary

Other Decks in Programming

Transcript

  1. Git In It
    BEGINNING TO USE GIT
    John Kary
    johnkary@
    gmail.com
    @
    johnkary
    Slides @ http://johnkary.net/talks

    View Slide

  2. Overview
    • Getting over the hurdle
    • Setting up your environment
    • Your first repository
    • Invest

    View Slide

  3. Part 1
    Getting over the hurdle
    Source: http://www.flickr.com/photos/keokiseu/4620268471/

    View Slide

  4. pre
    post

    View Slide

  5. git

    View Slide

  6. Chad Dickerson
    CEO @ Etsy
    RailsConf 2011 Keynote
    http://codeascraft.etsy.com/2011/06/06/optimizing-for-developer-happiness/
    Optimize for
    developer happiness.


    View Slide

  7. Excuses

    View Slide

  8. I keep backups.

    View Slide

  9. No, really, I keep backups.

    View Slide

  10. View Slide

  11. + 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...

    View Slide

  12. is Versioning
    NOT Version-Control

    View Slide

  13. I’ve tried _____

    View Slide

  14. I’ve tried _____

    View Slide

  15. I’ve tried _____

    View Slide

  16. I’ve tried _____

    View Slide

  17. I’ve tried _____

    View Slide

  18. I’ve tried _____
    it gets in the way
    of getting real work done

    View Slide

  19. Photo: 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

    View Slide

  20. Has anyone started using
    version control recently?

    View Slide

  21. Part 2
    Setting up your environment
    Source: http://www.flickr.com/photos/akahodag/3753216775/

    View Slide

  22. Install git
    http://git-scm.com/downloads

    View Slide

  23. Setup git
    https://help.github.com/articles/set-up-git

    View Slide

  24. Install git - Mac
    ~ $ brew install git
    ...
    ~ $ which git
    /usr/local/bin/git
    Homebrew
    The missing package manager for OS X
    http://mxcl.github.com/homebrew/

    View Slide

  25. Install git - Mac
    ~ $ 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

    View Slide

  26. Install git - Mac
    ~ $ 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

    View Slide

  27. Interacting with your repository

    View Slide

  28. For those already using git...
    Who is using a GUI?

    View Slide

  29. For those already using git...
    Who is using a CLI?

    View Slide

  30. git tower - http://www.git-tower.com

    View Slide

  31. Gitbox - http://www.gitboxapp.com/

    View Slide

  32. github for mac - http://mac.github.com/

    View Slide

  33. github for Windows - http://windows.github.com/

    View Slide

  34. Strongly
    STRONGLY
    encourage you to
    NOT
    use a GUI

    View Slide

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

    View Slide

  36. GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/

    View Slide

  37. GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/
    (master) ~/Sites/mysite $ gitx

    View Slide

  38. ~ $ 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

    View Slide

  39. Customizing your shell

    View Slide

  40. PS1
    ~ $ cat ~/.bash_profile
    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 $

    View Slide

  41. Part 3
    Your first repository
    Source: http://www.flickr.com/photos/nathaninsandiego/2584256116/

    View Slide

  42. Your first repository
    ~/Sites/beginning $ ls -la
    total 16
    drwxr-xr-x 4 johnkary staff 136 Jun 26 10:43 .
    drwxr-xr-x+ 113 johnkary staff 3842 Jun 26 10:42 ..
    -rw-r--r-- 1 johnkary staff 90 Jun 26 10:42 README
    -rw-r--r--@ 1 johnkary staff 210 Jun 26 10:44 index.html

    View Slide

  43. Your first repository
    ~/Sites/beginning $ git init
    Initialized empty Git repository in /Users/johnkary/Sites/beginning/.git/
    (master) ~/Sites/beginning $
    Create a git repository
    (master) ~/Sites/beginning $ ls -la
    total 16
    drwxr-xr-x 5 johnkary staff 170 Jun 26 10:50 .
    drwxr-xr-x+ 113 johnkary staff 3842 Jun 26 10:42 ..
    drwxr-xr-x 9 johnkary staff 306 Jun 26 10:50 .git
    -rw-r--r-- 1 johnkary staff 90 Jun 26 10:42 README
    -rw-r--r--@ 1 johnkary staff 210 Jun 26 10:44 index.html

    View Slide

  44. Your first repository
    (master) ~/Sites/beginning $ git add README
    (master) ~/Sites/beginning $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # (use "git rm --cached ..." to unstage)
    #
    # new file: README
    #
    # Untracked files:
    # (use "git add ..." to include in what will be committed)
    #
    # index.html
    Add a file to be committed

    View Slide

  45. Your first repository
    Source: http://git-scm.com/about/staging-area

    View Slide

  46. Your first repository
    (master) ~/Sites/beginning $ git commit -m "Add README"
    [master (root-commit) 4f6d22d] Add README
    1 file changed, 5 insertions(+)
    create mode 100644 README
    Commit our change
    (master) ~/Sites/beginning $ git status
    # On branch master
    # Untracked files:
    # (use "git add ..." to include in what will be committed)
    #
    # index.html
    nothing added to commit but untracked files present (use "git add" to track)

    View Slide

  47. Your first repository
    (master) ~/Sites/beginning $ git add index.html
    (master) ~/Sites/beginning $ git commit -m "Add prototype"
    [master 478eb5a] Add prototype
    1 file changed, 11 insertions(+)
    create mode 100644 index.html
    Commit our initial project prototype
    (master) ~/Sites/beginning $ git status
    # On branch master
    nothing to commit (working directory clean)

    View Slide

  48. Your first repository
    (master) ~/Sites/beginning $ git log
    commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85
    Author: John Kary
    Date: Tue Jun 26 11:19:30 2012 -0500
    Add prototype
    commit 4f6d22d25f8a59163c45e506cb0f8ecadcf918d0
    Author: John Kary
    Date: Tue Jun 26 11:10:35 2012 -0500
    Add README
    View your commit history

    View Slide

  49. Your first repository
    commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85
    Author: John Kary
    Date: Tue Jun 26 11:19:30 2012 -0500
    Add prototype
    (master) ~/Sites/beginning $ git commit -m "Add prototype"
    [master 478eb5a] Add prototype
    1 file changed, 11 insertions(+)
    create mode 100644 index.html
    Git SHA-1’s

    View Slide

  50. Your first repository
    commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85
    Author: John Kary
    Date: Tue Jun 26 11:19:30 2012 -0500
    Add prototype
    (master) ~/Sites/beginning $ git commit -m "Add prototype"
    [master 478eb5a] Add prototype
    1 file changed, 11 insertions(+)
    create mode 100644 index.html
    (master) ~/Sites/beginning $ git cat-file -p 478eb5a19fbd7fe7574942db285e0b2dff43fa85
    tree d7709a57c4668831d09bbbf69c7f1410ddeeae03
    parent 4f6d22d25f8a59163c45e506cb0f8ecadcf918d0
    author John Kary 1340727570 -0500
    committer John Kary 1340727570 -0500
    Add prototype
    Git SHA-1’s

    View Slide

  51. Your first repository
    More changes
    (master) ~/Sites/beginning $ git diff
    diff --git a/index.html b/index.html
    index edff44b..0765008 100644
    --- a/index.html
    +++ b/index.html
    @@ -2,10 +2,10 @@



    - My new project
    + Drupal KC


    - My new project
    + Drupal KC
    This project will change your life!

    View Slide

  52. Your first repository
    More changes
    (master) ~/Sites/beginning $ git add index.html
    (master) ~/Sites/beginning $ git status
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD ..." to unstage)
    #
    # modified: index.html
    #
    (master) ~/Sites/beginning $ git commit -m "Name project Drupal KC
    This is John's first idea for the project's name. Will be
    revising it as we go forward."
    [master 467350d] Name project Drupal KC
    1 file changed, 2 insertions(+), 2 deletions(-)

    View Slide

  53. Your first repository
    More changes
    (master) ~/Sites/beginning $ git log --oneline
    467350d Name project Drupal KC
    478eb5a Add prototype
    4f6d22d Add README

    View Slide

  54. Your first repository
    (master) ~/Sites/beginning $ gitx

    View Slide

  55. Your first repository
    (master) ~/Sites/beginning $ vim index.html
    (master) ~/Sites/beginning $ git diff
    diff --git a/index.html b/index.html
    index 0765008..a2bf6bf 100644
    --- a/index.html
    +++ b/index.html
    @@ -6,6 +6,10 @@


    Drupal KC
    +
    + About this project
    This project will change your life!
    +
    +

    View Slide

  56. Your first repository
    git add -p

    View Slide

  57. Your first repository
    (master) ~/Sites/beginning $ git add -p
    diff --git a/index.html b/index.html
    index 0765008..a2bf6bf 100644
    --- a/index.html
    +++ b/index.html
    @@ -6,6 +6,10 @@


    Drupal KC
    +
    + About this project
    This project will change your life!
    +
    +

    View Slide

  58. Your first repository
    Split into 2 hunks.
    @@ -6,4 +6,6 @@


    Drupal KC
    +
    + About this project
    This project will change your life!
    Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y

    View Slide

  59. Your first repository
    Split into 2 hunks.
    @@ -6,4 +6,6 @@


    Drupal KC
    +
    + About this project
    This project will change your life!
    Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
    @@ -9,3 +11,5 @@
    This project will change your life!
    +
    +

    View Slide

  60. Your first repository
    (master) ~/Sites/beginning $ git status
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD ..." to unstage)
    #
    # modified: index.html
    #
    # Changes not staged for commit:
    # (use "git add ..." to update what will be committed)
    # (use "git checkout -- ..." to discard changes in working directory)
    #
    # modified: index.html
    #
    (master) ~/Sites/beginning $ git commit -m “Add about heading”
    [master c580363] Add about heading
    1 file changed, 2 insertions(+)

    View Slide

  61. Your first repository
    (master) ~/Sites/beginning $ git add -p
    diff --git a/index.html b/index.html
    index 85a10ca..a2bf6bf 100644
    --- a/index.html
    +++ b/index.html
    @@ -9,5 +9,7 @@
    About this project
    This project will change your life!
    +
    +

    View Slide

  62. Your first repository
    (master) ~/Sites/beginning $ git log --oneline
    671829d Add company logo
    c580363 Add about heading
    467350d Name project Drupal KC
    478eb5a Add prototype
    4f6d22d Add README

    View Slide

  63. Part 4
    Invest
    Source: http://www.flickr.com/photos/tinavega/2896641451/

    View Slide

  64. Invest
    Official Git Docs
    http://git-scm.com/doc

    View Slide

  65. Invest
    Git Immersion
    http://gitimmersion.com

    View Slide

  66. Invest
    http://git-scm.com/book http://pragprog.com/book/tsgit/
    pragmatic-version-control-using-git

    View Slide

  67. Invest
    Getting Git
    By Scott Chacon
    http://blip.tv/scott-chacon/git-talk-4113729
    Source: http://www.flickr.com/photos/fraserspeirs/3389758506/

    View Slide

  68. START

    View Slide

  69. 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/
    Official Git Docs - http://git-scm.com/doc
    Git Immersion - http://gitimmersion.com
    Pro Git - http://git-scm.com/book
    Pragmatic Version Control Using Git - http://pragprog.com/book/tsgit/pragmatic-version-control-using-git
    Getting git by Scott Chacon - http://blip.tv/scott-chacon/git-talk-4113729
    Slides - http://johnkary.net/talks
    Resources

    View Slide

  70. Git In It
    BEGINNING TO USE GIT
    John Kary
    johnkary@
    gmail.com
    @
    johnkary
    Slides @ http://johnkary.net/talks

    View Slide