Introduction to Git (Greg Lonnon)

6,774 views

Published on

A brief introduction to Git as presented by Greg Lonnon at the January meetup of the Boise Web Technologies Group.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,774
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
36
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Introduction to Git (Greg Lonnon)

  1. 1. Git Intro
  2. 2. agenda <ul><li>source code management (SCM) tools
  3. 3. git </li><ul><li>design
  4. 4. usage </li></ul></ul>
  5. 5. Who is Greg? <ul><li>SCM geek... </li><ul><li>Sccs,rcs,cvs,svn,clearcase,perforce, and now git </li></ul><li>Master Architect @ HP </li><ul><li>FutureSmart product line </li><ul><li>enterprise imaging products </li></ul><li>YouTube FutureSmart Video </li></ul><li>I still use the <blink> tag... </li><ul><li>I don't care about IE... </li></ul></ul>
  6. 6. SCM??? <ul><li>Attributes of a SCM tool </li><ul><li>”Track” (folders and files) </li><ul><li>Individually or in sets (change sets) </li></ul><li>”Branch” </li><ul><li>Independent changes
  7. 7. Common starting points
  8. 8. Release, feature development, etc... </li></ul><li>”Merge” </li><ul><li>Combine 2..N branches into 1 </li></ul><li>”History” </li><ul><li>What, when, why questions </li></ul></ul></ul>
  9. 9. SCM Evolution tar/zip RCS SVN CVS clearcase perforce git/hg/bazaar
  10. 10. SCM: the new guys <ul><li>git, hg, bazaar
  11. 11. peer to peer architecture
  12. 12. atomic ”change set” based </li><ul><li>file changes are grouped together as a transaction </li></ul><li>takes advantage of local machine features </li><ul><li>CPU and Disk </li></ul></ul>
  13. 13. What is git? <ul><li>One of the new guys
  14. 14. A tree based content management storage system </li><ul><li>with SCM'ish commands </li></ul><li>Developed for Linux kernel </li><ul><li>Linus Torvald wrote the first version
  15. 15. Ported to Windows, OSX, any posix based OS
  16. 16. Many GUI clients </li></ul></ul>
  17. 17. git Storage Design <ul><li>git storage design is the key concept to understand
  18. 18. It's simple, based on... </li><ul><li>Cryptography theory
  19. 19. Database theory
  20. 20. Graph theory
  21. 21. Set theory </li></ul></ul>
  22. 22. git storage (repository) <ul>Object based Storage <ul><li>(Key,Data) tuple </li><ul><li>key = SHA1(data)
  23. 23. keys are 20 byte arrays.
  24. 24. SHA1 algorithm – crypto algorithm </li></ul><li>Data </li><ul><li>blobs : files, sym-links
  25. 25. trees : directories
  26. 26. commit : points to a tree, and other commits
  27. 27. tag : points to a commit </li></ul></ul></ul>
  28. 28. Git: blobs #include <stdio.h> int main() { printf(“hello world”); return 0; } Blobs: files (text and binary), symlinks
  29. 29. git: tree permission object hash name 100644 blob 82354a1... README 100755 blob 02342c5... a.out 040000 tree a67ef32... 02342c... src Trees: aka directories
  30. 30. git: commit date author parents comment tree Mon Dec 20 16:10:41 2010 -0700 joe developer <joe@gmail.com> 234ab23... Fixed the border defect 89023a2...
  31. 31. git: tag date tagger Mon Dec 20 16:10:41 2010 -0700 joe developer <joe@gmail.com> 234ab23... commit comment Release 1.0
  32. 32. git: repo git init echo “hello” > B1 git add B1 git commit echo “world” > B2 git add B2 git commit git init echo “hello” > B1 git add B1 git commit mkdir T2 git mv B1 B2 T2 cp T2/B1 B3 git add B3 git commit Time C3 C1 C2 T1 B2 B1 T1 T2 B2 B1 T1 B1 C3 C1 C2 T2 B2 B1 T3 T2 B2 B1 T1 B1
  33. 33. git: repo C3 C1 C2 T1 T1 T1 B1 C3 C1 C2 T2 B2 T3 T1 B1
  34. 34. git : DAG <ul><li>Wikipedia... </li><ul><li>In mathematics and computer science, a directed acyclic graph (commonly abbreviated to DAG), is a directed graph with no directed cycles. That is, it is formed by a collection of vertices and directed edges, each edge connecting one vertex to another, such that there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again.” </li></ul></ul>
  35. 35. git : DAG HEAD <ul><li>git references </li><ul><li>branches (master, work_br)
  36. 36. tags : immutable (V1.0) </li></ul></ul>C1 C1 C1 C2 C1 C3 C1 C6 C1 C8 C4 C5 C7 master work_br V1.0
  37. 37. git: DAG HEAD git init git commit C1 C1 master
  38. 38. git: DAG HEAD git branch work_br C1 C1 master work_br
  39. 39. git: DAG HEAD git commit C1 C1 C1 C2 master work_br
  40. 40. git: DAG HEAD git commit C1 C1 C1 C2 C1 C3 master work_br
  41. 41. git: DAG HEAD git checkout work_br git commit C1 C1 C1 C2 C1 C3 C4 master work_br
  42. 42. git: DAG HEAD git commit C1 C1 C1 C2 C1 C3 C4 C5 master work_br
  43. 43. git: DAG HEAD git checkout master git merge work_br C1 C1 C1 C2 C1 C3 C1 C6 C4 C5 master work_br
  44. 44. git: DAG HEAD git checkout work_br git commit C1 C1 C1 C2 C1 C3 C1 C6 C4 C5 C7 master work_br
  45. 45. git: DAG HEAD git checkout master git commit C1 C1 C1 C2 C1 C3 C1 C6 C1 C8 C4 C5 C7 master work_br
  46. 46. git repository <ul><li>Each git repo contains complete history </li><ul><li>All git objects are stored in the repo
  47. 47. Peer to Peer Design </li></ul><li>.git directory </li><ul><li>objects
  48. 48. references </li><ul><li>branches, tags : files that contain commit hash
  49. 49. HEAD : current checkout hash </li></ul></ul></ul>
  50. 50. git clone HEAD http:/github.com/<user>/<repo> origin git clone http://github.com/ <user>/<repo> local git clone copies the remote objects/references to a new repository The remote repo is nicknamed origin , a remote tracking branch is created to track origin/master local C1 C1 C2 C1 C3 C4 C5 master work_br C1 C1 C2 C1 C3 C4 C5 origin/master origin/work_br master
  51. 51. git fetch HEAD HEAD git fetch origin origin local local Fetch moves C6 commit objects to the local repo, and updates the tracking branch origin/master C1 C2 C3 C4 C5 master work_br C6 C1 C2 C3 C4 C5 origin/master work_br C1 C2 C3 C4 C5 origin/master work_br C6 C7 master master origin/work_br origin/work_br
  52. 52. git push git push origin origin Push local to origin. The local work_br is a proper superset of the origin work_br branch, and the origin is updated. The local master push fails, it is NOT a not a proper superset of the origin master branch origin HEAD local C1 C2 C3 C4 C5 master work_br C6 C1 C2 C3 C4 C5 master work_br C6 C7 C1 C2 C3 C4 C5 origin/master work_br C6 C7 master origin/work_br
  53. 53. git pull <ul><li>git pull </li><ul><li>git fetch + git merge </li></ul></ul>
  54. 54. git: merge algorithms <ul><li>git merge </li><ul><li>Merges 1..N branches into current branch (HEAD) </li></ul><li>git merge --squash </li><ul><li>” git merge” with no parent tracking (”merge tracking”) </li></ul><li>git cherry-pick </li><ul><li>Calculates the file differences of the commit and applies them to current branch (HEAD) </li></ul><li>git rebase </li><ul><li>Moves a related set of commits to a new ”base” reference. </li></ul></ul>
  55. 55. git merge HEAD git merge work_br HEAD Merges 1 or more branch into the current branch. C1 C1 C1 C2 C1 C3 C4 C5 master work_br C1 C1 C1 C2 C1 C3 C1 C6 C4 C5 master work_br
  56. 56. git merge --squash HEAD git merge --squash work_br HEAD Merges a branch, but does not track the merge. Useful in large repositories with a lot of activity. C1 C1 C1 C2 C1 C3 C4 C5 master work_br C1 C1 C1 C2 C1 C3 C1 C6 C4 C5 master work_br
  57. 57. git cherry-pick HEAD git cherry-pick C5 HEAD Calculates and applies the file changes of a commit. Useful for moving changes between a release branch and main development C1 C1 C1 C2 C1 C3 C4 C5 master work_br C1 C1 C1 C2 C1 C3 C4 C5 work_br C5' master
  58. 58. git rebase HEAD git rebase master HEAD Moves a “family” of commits to a new “base” Useful for developers to “refresh” their branch. C1 C1 C1 C2 C1 C3 C4 C5 master work_br C1 C1 C1 C2 C1 C3 C4 C5 master work_br C4' C5'
  59. 59. git rebase: a closer look HEAD Step 1: Apply d1 to C3 Step 2: Apply d2 to C4' C1 C1 C1 C2 C1 C3 C4 C5 master work_br C4' C5' d1 d2 d1 d2
  60. 60. git commands porcelain <ul><li>Repository </li><ul><li>git init, git clone, git fetch, git pull, git push, git gc, git config </li></ul><li>Working tree </li><ul><li>git checkout, git reset, git clean, git add, git commit </li></ul><li>Branch </li><ul><li>git branch, git tag, git merge, git rebase, git cherry-pick, git revert, git mergetool </li></ul><li>History </li><ul><li>git log, git diff, git difftool, git reflog </li></ul></ul>
  61. 61. git commands plumbing <ul><li>Git low level commands </li><ul><li>Easy to parse output
  62. 62. Stable API
  63. 63. Use them for scripting git
  64. 64. 100+ commands... </li></ul></ul>
  65. 65. gitk
  66. 66. git gui
  67. 67. git hints <ul><li>Commit </li><ul><li>When something compiles, passes a test, before refactoring, before going to lunch/home/sleep, or... when you have nothing else to do...
  68. 68. Use commits to separate out features, debug, temporary work, etc...
  69. 69. git != svn, don't treat it like svn...
  70. 70. Use git reflog to find ”lost commits” </li></ul><li>Create a sandbox (git init) and play... </li></ul>
  71. 71. git : Web Resources <ul><li>Use google... </li><ul><li>http://git-scm.com/ </li></ul><li>Free Pro Git book </li><ul><li>http://progit.org/book/ </li></ul><li>Free Webcasts </li><ul><li>http://gitcasts.com/
  72. 72. http://oreillynet.com/pub/e/1394 </li></ul><li>Free Open Source Hosting (cheap commerical hosting) </li><ul><li>https://github.com/ </li></ul><li>Gitolite : git server </li><ul><li>supports complex security models
  73. 73. https://github.com/sitaramc/gitolite </li></ul><li>Windows executable </li><ul><li>Git-extensions or msysgit </li></ul></ul>

×