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

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
  2. Overview • Getting over the hurdle • Setting up your

    environment • Your first repository • Invest
  3. git

  4. + 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...
  5. 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
  6. 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/
  7. 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
  8. 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
  9. git GUIs • Dumb-down underlying commands • Present limited command

    options • Not available on most remote servers • But there is one I recommend...
  10. ~ $ 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
  11. 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 $
  12. 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
  13. 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
  14. 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
  15. 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)
  16. 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)
  17. Your first repository (master) ~/Sites/beginning $ git log commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85

    Author: John Kary <[email protected]> Date: Tue Jun 26 11:19:30 2012 -0500 Add prototype commit 4f6d22d25f8a59163c45e506cb0f8ecadcf918d0 Author: John Kary <[email protected]> Date: Tue Jun 26 11:10:35 2012 -0500 Add README View your commit history
  18. Your first repository commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85 Author: John Kary <[email protected]> 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
  19. Your first repository commit 478eb5a19fbd7fe7574942db285e0b2dff43fa85 Author: John Kary <[email protected]> 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 <[email protected]> 1340727570 -0500 committer John Kary <[email protected]> 1340727570 -0500 Add prototype Git SHA-1’s
  20. 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>
  21. 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(-)
  22. Your first repository More changes (master) ~/Sites/beginning $ git log

    --oneline 467350d Name project Drupal KC 478eb5a Add prototype 4f6d22d Add README
  23. 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>
  24. 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
  25. 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
  26. 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
  27. 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(+)
  28. 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(+)
  29. 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
  30. 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
  31. Git In It BEGINNING TO USE GIT John Kary johnkary@

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