Introduction to Git
description
Transcript of Introduction to Git
![Page 1: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/1.jpg)
Introduction to Git
2011 F2E SummitJenny Donnelly, YUI
![Page 2: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/2.jpg)
• Git overview• Basic usage• Git, YUI, and GitHub• Real world tips and tricks
Introduction to Git
![Page 3: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/4.jpg)
Git is distributed
YUI 3
YUI 3
> git clone> git commit> git pull> git push
(origin)
![Page 5: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/5.jpg)
Git is distributed
YUI 3
YUI 3
YUI 3
YUI 3 YUI 3
![Page 6: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/6.jpg)
The YUI Workflow
YUI 3at Y!
Jenny
Luke
Dav
YUI 3 onGitHub
Contributor
![Page 7: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/7.jpg)
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.
![Page 8: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/8.jpg)
Git snapshots have integrity
Commit 1e933ga3e
Commit 24bc24eff
Commit 394e0dc2a
Commit 1e933ga3e
Commit 33de3b09f
Commit 2g3ea9cb3
Knock knock!
Go away!
Orange.
Knock knock!
Go away!
Banana.
Knock knock!
Who's there?
Banana.
Knock knock!
Go away!
Orange.
Knock knock!
Who's there?
Orange.
Knock knock!
Who's there?
Banana.
![Page 9: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/9.jpg)
Git makes branches easy
Commit X Commit A0 Commit An
Commit B0
Commit B1
Commit C
Commit Bn
![Page 10: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/10.jpg)
When to branch?
• For each version• For each fix• Explore multiple solutions• Collaborate• All the time!
![Page 11: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/11.jpg)
Branch workflow
bug1234
masterfeatureA
perf-exp1
doc-updates
perf-exp2
< Upstream Downstream >
![Page 12: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/12.jpg)
Recap
YUI 3at Y!
Jenny
Luke
Dav
YUI 3 onGitHub
Contributor
![Page 13: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/13.jpg)
Recap
bug1234
master featureA
bug3456
![Page 14: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/14.jpg)
Recap
Commit 1e933ga3e
Commit 24bc24eff
Commit 394e0dc2a
diff + parent = hash
![Page 15: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/15.jpg)
File states
Modified
------------
------------
------------
Staged
Committed
> git add file.txt
> vi file.txt
> git commit file.txt
94e0dc2a
![Page 16: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/16.jpg)
Edit files> vi joke.txt> git diffdiff --git a/joke.txt b/joke.txtindex 7f172de..4aaf7a3 100644--- a/joke.txt+++ b/joke.txt@@ -1,4 +1,4 @@ Knock knock!-Go away!+Who's there? Orange.
![Page 17: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/17.jpg)
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")
![Page 18: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/18.jpg)
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#
![Page 19: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/19.jpg)
Edit files> git commit -m "Reply with a question."
![Page 20: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/20.jpg)
Edit files> git commit
![Page 21: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/21.jpg)
Anatomy of a proper commit message
![Page 22: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/22.jpg)
Anatomy of a proper commit message
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
![Page 23: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/23.jpg)
Edit files> git commit[master 77dcfbc] Reply with a question.
1 files changed, 1 insertions(+), 1 deletions(-)
![Page 24: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/24.jpg)
Edit files> git logcommit 77dcfbcc318be5ef5b9af5f1865647db3566fd4aAuthor: Jenny Donnelly <[email protected]>
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.
...
![Page 25: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/25.jpg)
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.txtnothing added to commit but untracked files present (use "git add" to track)
> vi new.txt> git status
![Page 26: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/26.jpg)
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
![Page 27: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/27.jpg)
Remove files> git rm new.txt> git commit
![Page 28: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/28.jpg)
Rename files> git mv foo.txt bar.txt> git commit
![Page 29: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/29.jpg)
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
![Page 30: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/30.jpg)
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
![Page 31: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/31.jpg)
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
![Page 32: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/32.jpg)
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
![Page 33: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/33.jpg)
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
![Page 34: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/34.jpg)
master
bug1234
Syncing branches
Commit 0 Commit M1 Commit M2
Commit B1 Commit Bn
> git checkout bug1234> git rebase master
Commit
![Page 35: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/35.jpg)
master
bug1234
Syncing branches
Commit 0 Commit M1 Commit M2
Commit B1 Commit Bn
Commit
![Page 36: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/36.jpg)
master
bug1234
Syncing branches
Commit 0 Commit M1 Commit M2
Commit B1 Commit Bn
Commit
![Page 37: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/37.jpg)
master
bug1234
Syncing branches
Commit 0 Commit M1 Commit M2
Commit B1Commit Bn
Commit
![Page 38: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/38.jpg)
master
bug1234
Syncing branches
Commit 0 Commit M1 Commit M2
Commit B1 Commit Bn
Commit
![Page 39: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/39.jpg)
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!
![Page 40: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/40.jpg)
master
bug1234
Sending changes upstream
Commit 0 Commit M1 Commit M2
Commit B1 Commit B2
> git checkout master> git merge bug1234
Commit
![Page 41: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/41.jpg)
master
Sending changes upstream
Commit 0 Commit M1 Commit M2
bug1234Commit B1 Commit B2
Commit
Commit B1 Commit B2
![Page 42: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/42.jpg)
master
Sending changes upstream
Commit 0 Commit M1 Commit M2
bug1234Commit B1 Commit B2
Commit
Commit B1 Commit B2Commit M3
![Page 43: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/43.jpg)
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
![Page 44: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/44.jpg)
master
bug1234
Tip: Rebase, then merge
Commit 0 Commit M1 Commit M2
Commit B1 Commit B2
> git checkout bug1234> git rebase master
Commit
![Page 45: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/45.jpg)
master
bug1234
Tip: Rebase, then merge
Commit 0 Commit M1 Commit M2
Commit B2
Commit
Commit B1
> git checkout master> git merge bug1234
![Page 46: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/46.jpg)
master
Sending changes upstream
Commit 0 Commit M1 Commit M2
bug1234Commit B1 Commit B2
Commit
Commit B1 Commit B2
![Page 47: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/47.jpg)
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
![Page 48: Introduction to Git](https://reader036.fdocuments.in/reader036/viewer/2022062323/56815b1f550346895dc8d90b/html5/thumbnails/48.jpg)
More resourcesGit 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