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.

D3e3f4ac37c02289f5dfed115949fc88?s=128

John Kary

June 26, 2012
Tweet

Transcript

  1. Git In It BEGINNING TO USE GIT John Kary johnkary@

    gmail.com @ johnkary Slides @ http://johnkary.net/talks
  2. Overview • Getting over the hurdle • Setting up your

    environment • Your first repository • Invest
  3. Part 1 Getting over the hurdle Source: http://www.flickr.com/photos/keokiseu/4620268471/

  4. pre post

  5. git

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

    for developer happiness. “ ”
  7. Excuses

  8. I keep backups.

  9. No, really, I keep backups.

  10. None
  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...
  12. is Versioning NOT Version-Control

  13. I’ve tried _____

  14. I’ve tried _____

  15. I’ve tried _____

  16. I’ve tried _____

  17. I’ve tried _____

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

    real work done
  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
  20. Has anyone started using version control recently?

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

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

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

  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/
  25. Install git - Mac ~ $ man git-log GIT-LOG(1) Git

    Manual GIT-LOG(1) NAME git-log - Show commit logs SYNOPSIS git log [<options>] [<since>..<until>] [[--] <path>...] 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
  26. Install git - Mac ~ $ cat ~/.bash_profile source `brew

    --prefix git`/etc/bash_completion.d/git-completion.bash ~ $ source ~/.bash_profile ~ $ git sta<TAB><TAB> stage stash status ~ $ git sta Bash command auto-completion
  27. Interacting with your repository

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

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

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

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

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

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

  34. Strongly STRONGLY encourage you to NOT use a GUI

  35. git GUIs • Dumb-down underlying commands • Present limited command

    options • Not available on most remote servers • But there is one I recommend...
  36. GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/

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

  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
  39. Customizing your shell

  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 $
  41. Part 3 Your first repository Source: http://www.flickr.com/photos/nathaninsandiego/2584256116/

  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
  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
  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 <file>..." to unstage) # # new file: README # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # index.html Add a file to be committed
  45. Your first repository Source: http://git-scm.com/about/staging-area

  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 <file>..." to include in what will be committed) # # index.html nothing added to commit but untracked files present (use "git add" to track)
  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)
  48. Your first repository (master) ~/Sites/beginning $ git log commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85

    Author: John Kary <johnkary@foobar.com> Date: Tue Jun 26 11:19:30 2012 -0500 Add prototype commit 4f6d22d25f8a59163c45e506cb0f8ecadcf918d0 Author: John Kary <johnkary@foobar.com> Date: Tue Jun 26 11:10:35 2012 -0500 Add README View your commit history
  49. Your first repository commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85 Author: John Kary <johnkary@foobar.com> 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
  50. Your first repository commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85 Author: John Kary <johnkary@foobar.com> 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 <johnkary@foobar.com> 1340727570 -0500 committer John Kary <johnkary@foobar.com> 1340727570 -0500 Add prototype Git SHA-1’s
  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 @@ <html lang="ru-RU"> <head> <meta charset="UTF-8"> - <title>My new project</title> + <title>Drupal KC</title> </head> <body> - <h1>My new project</h1> + <h1>Drupal KC</h1> <p>This project will change your life!</p> </body>
  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 <file>..." 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(-)
  53. Your first repository More changes (master) ~/Sites/beginning $ git log

    --oneline 467350d Name project Drupal KC 478eb5a Add prototype 4f6d22d Add README
  54. Your first repository (master) ~/Sites/beginning $ gitx

  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 @@ </head> <body> <h1>Drupal KC</h1> + + <h2>About this project</h2> <p>This project will change your life!</p> + + <div><img src="logo.png" alt="Drupal KC"></div> </body>
  56. Your first repository git add -p

  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 @@ </head> <body> <h1>Drupal KC</h1> + + <h2>About this project</h2> <p>This project will change your life!</p> + + <div><img src="logo.png" alt="Drupal KC"></div> </body> </html> Stage this hunk [y,n,q,a,d,/,s,e,?]? s
  58. Your first repository Split into 2 hunks. @@ -6,4 +6,6

    @@ </head> <body> <h1>Drupal KC</h1> + + <h2>About this project</h2> <p>This project will change your life!</p> Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
  59. Your first repository Split into 2 hunks. @@ -6,4 +6,6

    @@ </head> <body> <h1>Drupal KC</h1> + + <h2>About this project</h2> <p>This project will change your life!</p> Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y @@ -9,3 +11,5 @@ <p>This project will change your life!</p> + + <div><img src="logo.png" alt="Drupal KC"></div> </body> </html> Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n
  60. Your first repository (master) ~/Sites/beginning $ git status # On

    branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: index.html # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." 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(+)
  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 @@ <h2>About this project</h2> <p>This project will change your life!</p> + + <div><img src="logo.png" alt="Drupal KC"></div> </body> </html> Stage this hunk [y,n,q,a,d,/,e,?]? y (master) ~/Sites/beginning $ git commit -m "Add company logo" [master 671829d] Add company logo 1 file changed, 2 insertions(+)
  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
  63. Part 4 Invest Source: http://www.flickr.com/photos/tinavega/2896641451/

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

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

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

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

  68. START

  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
  70. Git In It BEGINNING TO USE GIT John Kary johnkary@

    gmail.com @ johnkary Slides @ http://johnkary.net/talks