0
Git Magic:Versioning Files  Like a Boss  Tommy MacWilliam   tmacwilliam@cs50.net
Today• setting up like a boss• basic git like a boss• using branches like a boss• reverting changes like a boss• collabora...
Git is...• “Git is distributed version control system  focused on speed, effectivity and real-world  usability on large pr...
Git is...
Git is...Awesome.
Installing Git• Windows: http://code.google.com/p/  msysgit/• OS X: http://code.google.com/p/git-osx-  installer/• Applian...
Installing Gitroot@appliance(~): gitusage: git [--version] [--exec-path[=<path>]] [--html-path]       [-p|--paginate|--no-...
git config --globaluser.name“Tommy MacWilliam”
git config --globaluser.emailtmacwilliam@cs50.net
git init
Commits• snapshots of your project• what your files look like at a given point• single event in project history
git status
git add index.php
git add --all
git add --all
git add --allgit commit
Commit Messages• short message describing what’s different in  this commit• add any new features?• fix some bugs?• break an...
Commit Messages
Commit Messages• http://www.commitlogsfromlastnight.com/
git commit -a -m  “oh hi, mark!”
git log
5aeebab117b892fa42002146e4c62be676bc4621b43b0ad1e8108e7ab870d7a54feac93ae8b8600e461476587780aa9fa5611ea6dc3912c146a91760
Commit   5aeebab117b892fa42002146e4c62be676bc4621  ID         b43b0ad1e8108e7ab870d7a54feac93ae8b8600e         46147658778...
git show
git show b43b0
git initgit status git addgit commit   git log git show
git initgit status git addgit commit   git log git show
Branches• non-linear development process • changes on one branch do not affect    other branches• crazy idea? make a branc...
git branch test
git branch test
git branch testgit checkout test
5aeeb b43b0 46147master
5aeeb         git branch test b43b0      f862f 46147      36223master      test
git merge
5aeeb b43b0    f862f 46147    36223         git merge 87aedmaster    test
Like a boss.
git branch -D test
Merge vs. Rebase• git merge: new commit, non-linear history• git rebase: no new commit, linear history
5aeeb         git branch test b43b0      f862f 46147      36223master      test
5aeeb b43b0         git rebase 46147                f862f   36223master
Conflicts• change in one branch can be incompatible  with another• git tries to resolve, but sometimes cannot
Conflict Resolutionint main(int argc, char** argv) {   printf(“you invited all my friends”);}int main(int argc, char** argv...
Conflict Resolutionint main(int argc, char** argv) {   <<<<<<< HEAD:file.c   printf(“you invited all my friends”);   =======...
git checkout git branch git merge git rebase
git checkout git branch git merge git rebase
git commit -m “oops.”
git revert b43b0
5aeebb43b046147
5aeebb43b046147          git revert b43b0 42bb4(b43b0)
File-Specific Reverts• git checkout -- index.php • replace with version in index• git checkout b43b0 index.php • replace wi...
git reset --hard b43b0
git reflog
git bisect
Like a boss.
git revert  git resetgit checkout  git bisect
git revert  git resetgit checkout  git bisect
“distributed development”
ssh-keygen
git pushgit@github.com:cs50/project        master
git remote add origingit@github.com:cs50/project
git remote add origingit@github.com:cs50/projectgit push origin master
git clonegit@github.com:cs50/project
git pull origin master
git pull --rebase
git initgit add --allgit commit  Alice         Bob
git remote add origin urlgit push origin master Alice                      Bob
git remote add origin urlgit push origin master Alice                      Bob
git clone urlAlice          Bob
git clone urlAlice          Bob
git add --all        git commitAlice          Bob
git push origin masterAlice                 Bob
git push origin masterAlice                 Bob
git pull origin masterAlice                    Bob
git pull origin masterAlice                    Bob
git branch -a
git checkout -b   origin/test
scp ~/.ssh/id_rsa.pubhost:~/.ssh/authorized_keys
git init --bare
git remote add liveuser@cloud.cs50.net:~/project
git remote add liveuser@cloud.cs50.net:~/project  git push live master
Hooks•   applypatch-msg      •   post-applypatch•   commit-msg          •   pre-commit•   post-commit         •   pre-comm...
post-receive#!/bin/shGIT_WORK_TREE=/home/tmacwill/public_html git checkout -fchmod -R 644 /home/tmacwill/public_html/*.htm...
Like a boss.
git clonegit pushgit remote  git pull
git clonegit pushgit remote  git pull
More Resources• http://progit.org/book/• http://book.git-scm.com/• http://gitref.org/• http://git-scm.com/documentation
git commit -a -m     “thanks!”
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
Upcoming SlideShare
Loading in...5
×

Git Magic: Versioning Files like a Boss

1,926

Published on

Video available at: http://cs50.tv/2011/fall/seminars/Git_magic/Git_magic.mp4

Published in: Education, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,926
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • mkdir repo\nvim index.php: &lt;?php echo &amp;#x2018;git rocks&amp;#x2019;; ?&gt;\nvim page.php: &lt;?php echo &amp;#x2018;tommy does, too&amp;#x2019;; ?&gt;\ngit init\n
  • \n
  • git status\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git add --all\ngit commit\n
  • \n
  • \n
  • vim page2.php: &lt;?php echo &amp;#x2018;woo more commits&amp;#x2019;; ?&gt;\nvim index.php: &lt;?php echo &amp;#x2018;I made a change!&amp;#x2019;; ?&gt;\ngit add --all\ngit commit -m &amp;#x201C;another commit&amp;#x201D;\ngit log\n
  • \n
  • git show\ngit show PREVIOUS COMMIT\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git branch test\ngit branch\ngit checkout test\ngit branch\nvim crazy.php: &lt;?php echo &amp;#x2018;this is a crazy idea&amp;#x2019;; ?&gt;\ngit add --all\ngit commit -m &amp;#x201C;so crazy up in here&amp;#x201D;\nls\ngit log\ngit checkout master\nls\ngit log\n
  • \n
  • \n
  • git branch\ngit checkout master\nvim index.php: &lt;?php echo &amp;#x2018;this page is boring&amp;#x2019;; ?&gt;\ngit add --all\ngit commit -m &amp;#x201C;third commit on master&amp;#x201D;\ngit merge test\ngit log\n
  • git branch -D test\ngit branch\n
  • \n
  • \n
  • git log --graph\ncd ../rebased\ngit checkout master\ngit rebase test\ngit log --graph\ncd ../repo\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ls\ngit log\nvim index.php: &lt;?php echo &amp;#x2018;good idea&amp;#x2019;; ?&gt;\ngit commit -a -m &amp;#x201C;sweet&amp;#x201D;\nvim index.php: &lt;?php echo &amp;#x2018;bad idea&amp;#x2019;; ?&gt;\ngit commit -a -m &amp;#x201C;oops&amp;#x201D;\ngit revert to commit &amp;#x201C;sweet&amp;#x201D;\nCONFLICT!\ngit status\nvim index.php\ngit commit -a -m &amp;#x201C;revert&amp;#x201D;\ngit log\n
  • vim index.php: &lt;?php echo &amp;#x2018;only gonna add this&amp;#x2019;; ?&gt;\ngit add --all\ngit checkout -- index.php\nvim index.php\ngit checkout &lt;commit with &amp;#x201C;sweet&amp;#x201D;&gt; index.php\nvim index.php\n
  • git reset --hard HEAD\n
  • git checkout &lt;commit with &amp;#x201C;another commit&amp;#x201D;&gt;\ngit log\ngit reflog\ngit checkout master\n
  • git bisect good &lt;first commit&gt;\ngit bisect bad HEAD\ngit bisect bad\ngit checkout master\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git remote add origin git@github.com:tmac721/seminar.git\ngit remote\ngit remote show origin\ngit push origin master\n
  • cd ../\ngit clone git@github.com:tmac721/seminar.git\ncd test\nls\ngit log\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ssh cloud\nmkdir repo\ncd repo\ngit init --bare\ncd hooks\nvim post-receive: copy this\nchmod a+x post-receive\ngit remote add origin ssh://tmacwill@cloud.cs50.net/home/tmacwill/repo\ngit push origin master\n\n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "Git Magic: Versioning Files like a Boss"

    1. 1. Git Magic:Versioning Files Like a Boss Tommy MacWilliam tmacwilliam@cs50.net
    2. 2. Today• setting up like a boss• basic git like a boss• using branches like a boss• reverting changes like a boss• collaborating like a boss
    3. 3. Git is...• “Git is distributed version control system focused on speed, effectivity and real-world usability on large projects” • “distributed development” • “non-linear development” • “efficient handling of large projects” • “cryptographic authentication of history”
    4. 4. Git is...
    5. 5. Git is...Awesome.
    6. 6. Installing Git• Windows: http://code.google.com/p/ msysgit/• OS X: http://code.google.com/p/git-osx- installer/• Appliance: already installed!
    7. 7. Installing Gitroot@appliance(~): gitusage: git [--version] [--exec-path[=<path>]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [-c name=value] [--help] <command> [<args>]
    8. 8. git config --globaluser.name“Tommy MacWilliam”
    9. 9. git config --globaluser.emailtmacwilliam@cs50.net
    10. 10. git init
    11. 11. Commits• snapshots of your project• what your files look like at a given point• single event in project history
    12. 12. git status
    13. 13. git add index.php
    14. 14. git add --all
    15. 15. git add --all
    16. 16. git add --allgit commit
    17. 17. Commit Messages• short message describing what’s different in this commit• add any new features?• fix some bugs?• break anything?
    18. 18. Commit Messages
    19. 19. Commit Messages• http://www.commitlogsfromlastnight.com/
    20. 20. git commit -a -m “oh hi, mark!”
    21. 21. git log
    22. 22. 5aeebab117b892fa42002146e4c62be676bc4621b43b0ad1e8108e7ab870d7a54feac93ae8b8600e461476587780aa9fa5611ea6dc3912c146a91760
    23. 23. Commit 5aeebab117b892fa42002146e4c62be676bc4621 ID b43b0ad1e8108e7ab870d7a54feac93ae8b8600e 461476587780aa9fa5611ea6dc3912c146a91760HEAD
    24. 24. git show
    25. 25. git show b43b0
    26. 26. git initgit status git addgit commit git log git show
    27. 27. git initgit status git addgit commit git log git show
    28. 28. Branches• non-linear development process • changes on one branch do not affect other branches• crazy idea? make a branch• didn’t work? delete the branch• all done? merge the branch
    29. 29. git branch test
    30. 30. git branch test
    31. 31. git branch testgit checkout test
    32. 32. 5aeeb b43b0 46147master
    33. 33. 5aeeb git branch test b43b0 f862f 46147 36223master test
    34. 34. git merge
    35. 35. 5aeeb b43b0 f862f 46147 36223 git merge 87aedmaster test
    36. 36. Like a boss.
    37. 37. git branch -D test
    38. 38. Merge vs. Rebase• git merge: new commit, non-linear history• git rebase: no new commit, linear history
    39. 39. 5aeeb git branch test b43b0 f862f 46147 36223master test
    40. 40. 5aeeb b43b0 git rebase 46147 f862f 36223master
    41. 41. Conflicts• change in one branch can be incompatible with another• git tries to resolve, but sometimes cannot
    42. 42. Conflict Resolutionint main(int argc, char** argv) { printf(“you invited all my friends”);}int main(int argc, char** argv) { printf(“good thinking!”);}
    43. 43. Conflict Resolutionint main(int argc, char** argv) { <<<<<<< HEAD:file.c printf(“you invited all my friends”); ======= printf(“good thinking!”); >>>>>>> f862f:file.c}
    44. 44. git checkout git branch git merge git rebase
    45. 45. git checkout git branch git merge git rebase
    46. 46. git commit -m “oops.”
    47. 47. git revert b43b0
    48. 48. 5aeebb43b046147
    49. 49. 5aeebb43b046147 git revert b43b0 42bb4(b43b0)
    50. 50. File-Specific Reverts• git checkout -- index.php • replace with version in index• git checkout b43b0 index.php • replace with version in commit b43b0
    51. 51. git reset --hard b43b0
    52. 52. git reflog
    53. 53. git bisect
    54. 54. Like a boss.
    55. 55. git revert git resetgit checkout git bisect
    56. 56. git revert git resetgit checkout git bisect
    57. 57. “distributed development”
    58. 58. ssh-keygen
    59. 59. git pushgit@github.com:cs50/project master
    60. 60. git remote add origingit@github.com:cs50/project
    61. 61. git remote add origingit@github.com:cs50/projectgit push origin master
    62. 62. git clonegit@github.com:cs50/project
    63. 63. git pull origin master
    64. 64. git pull --rebase
    65. 65. git initgit add --allgit commit Alice Bob
    66. 66. git remote add origin urlgit push origin master Alice Bob
    67. 67. git remote add origin urlgit push origin master Alice Bob
    68. 68. git clone urlAlice Bob
    69. 69. git clone urlAlice Bob
    70. 70. git add --all git commitAlice Bob
    71. 71. git push origin masterAlice Bob
    72. 72. git push origin masterAlice Bob
    73. 73. git pull origin masterAlice Bob
    74. 74. git pull origin masterAlice Bob
    75. 75. git branch -a
    76. 76. git checkout -b origin/test
    77. 77. scp ~/.ssh/id_rsa.pubhost:~/.ssh/authorized_keys
    78. 78. git init --bare
    79. 79. git remote add liveuser@cloud.cs50.net:~/project
    80. 80. git remote add liveuser@cloud.cs50.net:~/project git push live master
    81. 81. Hooks• applypatch-msg • post-applypatch• commit-msg • pre-commit• post-commit • pre-commit-msg• post-receive • pre-rebase• post-update • update
    82. 82. post-receive#!/bin/shGIT_WORK_TREE=/home/tmacwill/public_html git checkout -fchmod -R 644 /home/tmacwill/public_html/*.htmlchmod -R 600 /home/tmacwill/public_html/*.php
    83. 83. Like a boss.
    84. 84. git clonegit pushgit remote git pull
    85. 85. git clonegit pushgit remote git pull
    86. 86. More Resources• http://progit.org/book/• http://book.git-scm.com/• http://gitref.org/• http://git-scm.com/documentation
    87. 87. git commit -a -m “thanks!”
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×