1 / 49

Introduction to Git

Introduction to Git. 2011 F2E Summit Jenny Donnelly, YUI. Git overview Basic usage Git, YUI, and GitHub Real world tips and tricks. Introduction to Git. Git is a version control system. Track changes (who/what/when) Compare versions Revert changes Perform merges

tuwa
Download Presentation

Introduction to Git

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Git 2011 F2E Summit Jenny Donnelly, YUI

  2. Git overview Basic usage Git, YUI, and GitHub Real world tips and tricks Introduction to Git

  3. Git is a version control system Track changes (who/what/when) Compare versions Revert changes Perform merges Implement tags and branches http://en.wikipedia.org/wiki/Revision_control

  4. Git is distributed YUI 3 (origin) YUI 3 > git clone > git commit > git pull > git push

  5. Git is distributed YUI 3 YUI 3 YUI 3 YUI 3 YUI 3

  6. The YUI Workflow YUI 3 at Y! YUI 3 on GitHub Dav Jenny Luke Contributor

  7. Git is a series of snapshots Commit 1 Commit 2 Commit 3 Knock knock! Go away! Orange. Knock knock! Who's there? Orange. Knock knock! Who's there? Banana.

  8. Git snapshots have integrity Commit 1 e933ga3e Commit 2 4bc24eff Commit 3 94e0dc2a Commit 1 e933ga3e Commit 3 3de3b09f Commit 2 g3ea9cb3 Knock knock! Go away! Orange. Knock knock! Who's there? Orange. Knock knock! Who's there? Banana. Knock knock! Go away! Orange. Knock knock! Go away! Banana. Knock knock! Who's there? Banana.

  9. Git makes branches easy Commit X Commit A0 Commit An Commit C Commit B0 Commit B1 Commit Bn

  10. When to branch? For each version For each fix Explore multiple solutions Collaborate All the time!

  11. Branch workflow bug1234 featureA perf-exp2 master perf-exp1 Downstream > < Upstream doc- updates

  12. Recap YUI 3 at Y! YUI 3 on GitHub Dav Jenny Luke Contributor

  13. Recap bug1234 featureA master bug3456

  14. Recap Commit 1 e933ga3e Commit 2 4bc24eff Commit 3 94e0dc2a diff + parent = hash

  15. File states ---- ---- ---- ---- ---- ---- ---- ---- ---- Modified > vi file.txt Staged > git add file.txt Committed > git commit file.txt 94e0dc2a

  16. Edit files > vi joke.txt > git diff diff --git a/joke.txt b/joke.txt index 7f172de..4aaf7a3 100644 --- a/joke.txt +++ b/joke.txt @@ -1,4 +1,4 @@ Knock knock! -Go away! +Who's there? Orange.

  17. Edit files > git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: joke.txt # no changes added to commit (use "git add" and/or "git commit -a")

  18. Edit files > git add joke.txt > git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: joke.txt #

  19. Edit files > git commit -m "Reply with a question."

  20. Edit files > git commit

  21. Anatomy of a proper commit message

  22. Anatomy of a proper commit message http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

  23. Edit files > git commit [master 77dcfbc] Reply with a question. 1 files changed, 1 insertions(+), 1 deletions(-)

  24. Edit files > git log commit 77dcfbcc318be5ef5b9af5f1865647db3566fd4a Author: Jenny Donnelly <jennydonnelly@yahoo-inc.com> Date: Thu Mar 24 17:03:36 2011 -0700 Reply with a question. I thought of a better reply. If I ask a question, it continues the dialog. Then maybe knocker can respond with something funny. ...

  25. New files > vi new.txt > git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # new.txt nothing added to commit but untracked files present (use "git add" to track) > vi new.txt > git status

  26. New files > git add new.txt > git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: new.txt # > git commit

  27. Remove files > git rm new.txt > git commit

  28. Rename files > git mv foo.txt bar.txt > git commit

  29. The “modified” state Diff from the last commit Follows you from branch to branch Moved, not copied Merge conflicts prevent checkout to another branch > git diff

  30. The “staged” state Very similar to "modified" state Diffs have been staged with> git add .> git add file.txt > git diff --cached Skip with> git commit -a

  31. The “committed” state Commits are snapshots Uniquely identified by SHA-1 hashes Hashes are diffs + parent Commits are sticky to branch > git whatchanged master..branch

  32. Recap: Commit workflow > vi joke.txt > git diff > git commit –a > git status > vi new.txt > git add new.txt > git commit > git status > git rm new.txt > git commit > git status

  33. Syncing branches workflow > git checkout master # start fresh > git pull > git checkout –b bug1234 > vi bugfix.txt > git commit –a > git checkout master > git pull # new commits come down

  34. Syncing branches master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit Bn > git checkout bug1234 > git rebase master

  35. Syncing branches master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit Bn

  36. Syncing branches master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit Bn

  37. Syncing branches master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit Bn

  38. Syncing branches master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit Bn

  39. Recap: Rebase Rewinds branchB Fast-forwards branchB to new HEAD of master Replays branchB commits Assumes upstream is vetted Rearranges branchB's history Branch B's commits receive new hashes Great for keeping downstream branches in sync with upstream changes Do NOT rebase once commits have been pushed upstream!

  40. Sending changes upstream master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit B2 > git checkout master > git merge bug1234

  41. Sending changes upstream master Commit Commit 0 Commit M1 Commit M2 Commit B1 Commit B2 bug1234 Commit B1 Commit B2

  42. Sending changes upstream master Commit Commit 0 Commit M1 Commit M2 Commit M3 Commit B1 Commit B2 bug1234 Commit B1 Commit B2

  43. Merging updates Unifies 2 or more histories All branches treated as equals Preserves all existing hashes Creates extra merge commit pointing to multiple parents Great for updating upstream branches with downstream changes

  44. Tip: Rebase, then merge master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit B2 > git checkout bug1234 > git rebase master

  45. Tip: Rebase, then merge master Commit Commit 0 Commit M1 Commit M2 bug1234 Commit B1 Commit B2 > git checkout master > git merge bug1234

  46. Sending changes upstream master Commit Commit 0 Commit M1 Commit M2 Commit B1 Commit B2 bug1234 Commit B1 Commit B2

  47. Recap: Branch workflow > git checkout master > git pull > git checkout –b bug1234 > vi bugfix.txt > git commit –a > git checkout master > git pull > git checkout bug1234 > git rebase master > run unittest.txt > git checkout master > git merge bug1234 > git push > git branch –d bug1234

  48. More resources Git Basics http://book.git-scm.com/index.html http://progit.org/book/ http://www.kernel.org/pub/software/scm/git/docs/ Contributing to YUI http://developer.yahoo.com/yui/theater/video.php?v=glass-yuiconf2009-contributing http://yuilibrary.com/gitfaq/ More Git http://gitready.com/ http://www.eecs.harvard.edu/~cduan/technical/git/ http://gitster.livejournal.com/tag/git

  49. I am... Jenny Donnelly, YUI jennydonnelly@yahoo-inc.com @jennyd

More Related