git going with dvcs v1.3
DESCRIPTION
An updated introduction to the Git Distributed Version Control System. Be prepared to have everything you know about centralized VCS systems turned upside down, but all for the benefit of easy of use, better team-mate interactions, and more robust (guaranteed) repository integrity and uptime.TRANSCRIPT
by Matthew McCullough of Ambient Ideas, LLC
with DVCSGit going
90 minutes of mental spoon bending
via source code control
Git-nounBritish Slang. an unpleasant or
contemptible person
-Oxford English Dictionary
“
”
I'm an egotistical bastard, and
I name all my projects
after myself. First Linux,
now git.-Linus Torvalds
“
”
RCS
Folders
CVSPVCS
ClearCaseSource
Safe
RCS
Folders
CVS
BitKeeperSubversion
PVCS
PerforceClearCaseSource
Safe
RCS
Folders
CVS
BitKeeperSubversion
PVCS
PerforceClearCaseSource
Safe
Mercurial
Bazaar
RCS
Folders
darcs
GitSource Code Control
Git Source Code Control
CultureChange
CentralizedVCS =Don’t
Innovate
Experiment
Safely Be Wrong
Drive-by Assist
Crowd Source
git config --global user.name "Hal Smith"
Global Git Settings
git config --global user.name "Hal Smith"
git config --global user.email "[email protected]"
Global Git Settings
git config --global user.name "Hal Smith"
git config --global user.email "[email protected]"
git config --list
Global Git Settings
◀Output current values
mkdir myproj.git
Creating a Repo
mkdir myproj.git
cd myproj.git
Creating a Repo
mkdir myproj.git
cd myproj.git
git init ◀That’s it folks
!
Creating a Repo
Who’s Got Git?
Hashes andIntegrity
Index vs. Hash‣ Centralized VCS uses DB auto-increment index.‣ Git uses SHA-1 hash.‣ Hash for the sake of integrity.
Hashable Objects‣ Blob‣ Tree‣ Commit‣ Tag
SHA-1 Hash
Index vs. Hash‣ Centralized VCS uses DB auto-increment index.‣ Git uses SHA-1 hash.‣ Hash for the sake of integrity.
Hashable Objects‣ Blob‣ Tree‣ Commit‣ Tag
SHA-1 Hash
I thought
hashes were
for
passwords?
http://book.git-scm.com/1_the_git_object_model.html
http://book.git-scm.com/1_the_git_object_model.html
http://book.git-scm.com/1_the_git_object_model.html
http://book.git-scm.com/1_the_git_object_model.html
BobAliceCentralized
BobAlice1 = okay.htm
Centralized
BobAlice1 = okay.htm
2 = fine.htm
Centralized
BobAlice1 = okay.htm
2 = fine.htm Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
1 = okay.htm
2 = fine.htm Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
3 = good.htm
1 = okay.htm
2 = fine.htm Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
3 = good.htm
1 = okay.htm
2 = fine.htm
3 = great.htm
Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
3 = good.htm
1 = okay.htm
2 = fine.htm
3 = great.htm
Sync
Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
3 = good.htm
1 = okay.htm
2 = fine.htm
3 = great.htm
4 = good.htm
4 = great.htm
Sync
Sync
Centralized
BobAlice1 = okay.htm
2 = fine.htm
3 = good.htm
1 = okay.htm
2 = fine.htm
3 = great.htm
4 = good.htm
4 = great.htm
Sync
Sync
Centralized
ERRORERROR
BobAliceDistributed
BobAlicea233b76 = okay.htm
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm Sync
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
a233b76 = okay.htm
d234ab1 = fine.htm Sync
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
f90b12c = good.htm
a233b76 = okay.htm
d234ab1 = fine.htm Sync
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
f90b12c = good.htm
a233b76 = okay.htm
d234ab1 = fine.htm
ae42ba0 = great.htm
Sync
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
f90b12c = good.htm
a233b76 = okay.htm
d234ab1 = fine.htm
ae42ba0 = great.htm
Sync
Sync
Distributed
BobAlicea233b76 = okay.htm
d234ab1 = fine.htm
f90b12c = good.htm
a233b76 = okay.htm
d234ab1 = fine.htm
ae42ba0 = great.htm ae42ba0 = great.htm
f90b12c = good.htm
Sync
Sync
Distributed
Integrity‣ Identifies damaged repos.‣ Prevents modification of published history.‣ Unique to file size and contents.
Tags‣ Cryptographically sign tags by GPG/email.
Independence‣ Separation from sequence # of checkin.
Hash Benefits
Location,Location,Location
Subversion‣ svn commit‣ Adds everything modified.‣ Must list if you want specific files.‣ What if you check in your password?
Single Stage Thinking
$ echo //password >> Matt1.java$ echo //password >> Matt2.java
$ echo //password >> Matt1.java$ echo //password >> Matt2.java
$ svn statusM Matt1.javaM Matt2.java
$ echo //password >> Matt1.java$ echo //password >> Matt2.java
$ svn statusM Matt1.javaM Matt2.java
$ svn commit -m'Matts checkin'Adding Matt1.javaAdding Matt2.javaTransmitting file data .Committed revision 2.
Repo
is like a special
IndexWorking
Stash Rem
ote
Repo
is like a special
IndexWorking
Stash Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
git stash apply
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
git stash apply
git add
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
git stash apply
git add
git commit
Rem
ote
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
git stash apply
git add
git commit
Rem
ote
git push
Repo
is like a special
IndexWorking
Stash
git clone
git checkout
edit some files
git stash
edit some files
git stash apply
git add
git commit
Rem
ote
git push
git clone git://somedomain/myproj.gitcd myproj.git
◀Build repo
git clone git://somedomain/myproj.gitcd myproj.git
git checkout master
◀Build repo
◀Update index
git clone git://somedomain/myproj.gitcd myproj.git
git checkout master
echo ‘//Comments’ >> ClassOne.javaecho ‘//Thoughts’ >> ClassTwo.java
◀Build repo
◀Update index
◀Edit working
git clone git://somedomain/myproj.gitcd myproj.git
git checkout master
echo ‘//Comments’ >> ClassOne.javaecho ‘//Thoughts’ >> ClassTwo.java
git add ClassOne.javagit commit -m’Added comments’
◀Build repo
◀Update index
◀Edit working
◀Add to index
◀Save to repo
git clone git://somedomain/myproj.gitcd myproj.git
git checkout master
echo ‘//Comments’ >> ClassOne.javaecho ‘//Thoughts’ >> ClassTwo.java
git add ClassOne.javagit commit -m’Added comments’
git stash
◀Build repo
◀Update index
◀Edit working
◀Add to index
◀Save to repo
◀Push to stash
Git‣ git add‣ git commit‣ git push‣ Commits only what is added to the index.‣ Opportunity to change history locally.‣ Selectively share with other repos.
Three Stage Thinking
$ echo //SECRETPASSWORD >> mattfile1.txt$ echo //NewText2 >> mattfile2.txt
$ echo //SECRETPASSWORD >> mattfile1.txt$ echo //NewText2 >> mattfile2.txt
$ git status# On branch master# Changed but not updated:# modified: mattfile1.txt# modified: mattfile2.txt
$ echo //SECRETPASSWORD >> mattfile1.txt$ echo //NewText2 >> mattfile2.txt
$ git status# On branch master# Changed but not updated:# modified: mattfile1.txt# modified: mattfile2.txt
$ git add mattfile1.txt ◀Put into index
$ echo //SECRETPASSWORD >> mattfile1.txt$ echo //NewText2 >> mattfile2.txt
$ git status# On branch master# Changed but not updated:# modified: mattfile1.txt# modified: mattfile2.txt
$ git add mattfile1.txt
$ git commit -m'Matts pw checkin'[master]: created ddcdf18: "Matts changes" 1 files changed, 1 insertions(+), 0 deletions(-)
◀Put into index
◀Save to repo
#$%^&!I just committed my password!
$ git reset --hard HEAD^HEAD is now at 9de4cd3 First checkin
$ git logcommit 9de4cd3a3f24a3de3e804df84cc3321c7d0c9993Author: Matthew McCullough <[email protected]>Date: Wed Mar 4 23:09:17 2009 -0700 First checkin
Change History
$ git reset --hard HEAD^HEAD is now at 9de4cd3 First checkin
$ git logcommit 9de4cd3a3f24a3de3e804df84cc3321c7d0c9993Author: Matthew McCullough <[email protected]>Date: Wed Mar 4 23:09:17 2009 -0700 First checkin
Change History
◀Throw away the commit
$ git reset --hard HEAD^HEAD is now at 9de4cd3 First checkin
$ git logcommit 9de4cd3a3f24a3de3e804df84cc3321c7d0c9993Author: Matthew McCullough <[email protected]>Date: Wed Mar 4 23:09:17 2009 -0700 First checkin
Change History
◀Throw away the commit
GitMathematics
a32
2e2
8b3
4e8
Directed Acyclic Graph
a32
2e2
5fa
8b3
4e8
Ann’s Feature
Directed Acyclic Graph
a32
2e2
5fa
8b3
4e8
Ann’s Feature
Directed Acyclic Graph
a32
2e2
5fa
8b3
4e8
Ann’s Feature
Tim’s Feature
Directed Acyclic Graph
d19
a32
2e2
5fa
8b3
4e8
e69
Ann’s Feature
Tim’s Feature
Directed Acyclic Graph
Linus’ rewrite of Tim’s feature
d19
a32
2e2
5fa
8b3
4e8
e69
Ann’s Feature
Tim’s Feature
Directed Acyclic Graph
Linus’ rewrite of Tim’s feature
d19
Sharing
Network‣ git instaweb. Built in, read-only, HTTP.
‣ git daemon. Custom socket language.
‣ gitosis. Easy permissions control.
‣ github. Open source & private repos.
‣ ssh. OS controlled permissions.
Serving It Up
Filesystem‣ Local folders. Yes, they can be “remotes.”
‣ Mapped network drives. Just like folders.
Serving It Up
git clone git://somehost.org/myproj.git ◀git daemon
git clone git://somehost.org/myproj.git
git clone [email protected]:myproj.git
git clone http://somehost.org/myproj.git
◀git daemon
◀SSH
◀HTTP
git clone git://somehost.org/myproj.git
git clone [email protected]:myproj.git
git clone http://somehost.org/myproj.git
git clone ~/work/myproj.git
◀git daemon
◀SSH
◀HTTP
◀Filesystem
git clone git://somehost.org/myproj.git
git clone [email protected]:myproj.git
git clone http://somehost.org/myproj.git
git clone ~/work/myproj.git
git clone z:\someserver\myproj.git
◀git daemon
◀SSH
◀HTTP
◀Filesystem
◀Network drive
Merge & Rebase
Cheap Branches
git show-branch --allgit branch -a
‣Local branch‣localbranchname‣Remote‣remote/branchname
Cheap Branches
Merge Anything
git merge --no-commit <sourcebranch>git merge --squash <sourcebranch>git merge <sourcebranch1> <sourcebranch2>
‣Selectable merge strategy‣Octopus: More than one ‣Review before committing‣Flatten micro-checkins
Merge Anything
Merge Strategies
Rebase for Clarity
git checkout myfeaturebranchgit rebase master
‣Cleaner history than a merge‣Fast forwards original branch‣Lets you see “how trunk will act” before you merge
Rebase for Clarity
WorkingOffline
Checkin
Offline Anything
CheckinAddBranchList change logGrep historyRewrite historyStashMergeLabelRemove
Offline Anything
CheckinAddBranchList change logGrep historyRewrite historyStashMergeLabelRemovepractically everything but push
Offline Anything
CheckinAddBranchList change logGrep historyRewrite historyStashMergeLabelRemovepractically everything but push
Offline Anything
Hooray! Another checkin to my latest OSS
project!
Hooray! Another checkin to my latest OSS
project!
I think I liked subversion better...
Speed
data from http://whygitisbetterthanx.com/#git-is-fast
git hg bzr
Init
git hg bzr
Add
git hg bzr
Status
git hg bzr
Diff
git hg bzr
Tag
git hg bzr
Log
git hg bzr
Commit (Lg)
git hg bzr
Commit (Sm)
git c git h hg c hg h bzr c bzr h
Branch (Cold/Hot)
VCS Interop
git svn clone http://unfurl.com/trunkgit svn dcommit
‣ First class compatibility.
‣ Round trip support.
‣ Git commits = svn commits.
Subversion
UsageModels
Central Repo
Ce
nt
ra
liz
ed
Central Repo
Ce
nt
ra
liz
ed
Blessed Repo
Dic
ta
to
rs
hip
Blessed Repo
Dic
ta
to
rs
hip
Blessed Repo
Dic
ta
to
rs
hip
Blessed Repo
Dic
ta
to
rs
hip
Blessed Repo
Dic
ta
to
rs
hip
Certified Repo
Development Repo
Int
eg
ra
tio
n M
an
ag
ed
Certified Repo
Development Repo
Int
eg
ra
tio
n M
an
ag
ed
Certified Repo
Development Repo
Int
eg
ra
tio
n M
an
ag
ed
Certified Repo
Development Repo
Int
eg
ra
tio
n M
an
ag
ed
Mirror
Development Repo
Mir
ro
re
d
Mirror
Certified Repo
Mirror
Development Repo
Mir
ro
re
d
Mirror
Certified Repo
Mirror
Development Repo
Mir
ro
re
d
Mirror
Certified Repo
Mirror
Development Repo
Mir
ro
re
d
Mirror
Certified Repo
Mirror
Development Repo
Mir
ro
re
d
Mirror
Certified Repo
Cu
st
om
+ P
ub
lic
Co
nt
rib
☚ P
riva
te
Pub
lic ☛
GitHub
Cu
st
om
+ P
ub
lic
Co
nt
rib
☚ P
riva
te
Pub
lic ☛
GitHub
Cu
st
om
+ P
ub
lic
Co
nt
rib
Customized
☚ P
riva
te
Pub
lic ☛
GitHub
Cu
st
om
+ P
ub
lic
Co
nt
rib
Customized
☚ P
riva
te
Pub
lic ☛
GitHub
Cu
st
om
+ P
ub
lic
Co
nt
rib
Customized
☚ P
riva
te
Pub
lic ☛
GitHub
GUIs
GitX
gitSafe
GitK
GitGUI
reasons6
❻‣git cherry-pick a5b2ee
Cherry Pick
❻‣git cherry-pick a5b2ee
‣Merge in just one commit.
Cherry Pick
❻‣git cherry-pick a5b2ee
‣Merge in just one commit.
‣When you want a nugget, not a branchload.
Cherry Pick
❺‣Tracks who authors a change.
Gives Credit
❺‣Tracks who authors a change.
‣“Author” even survives passing through reviewers.
Gives Credit
❺‣Tracks who authors a change.
‣“Author” even survives passing through reviewers.
‣“Author” survives all merges.
Gives Credit
❺‣Tracks who authors a change.
‣“Author” even survives passing through reviewers.
‣“Author” survives all merges.
‣Additionally tracks who committed a change.
Gives Credit
❹‣git bisect run mvn test
Bisect Bugs
❹‣git bisect run mvn test
‣Binary-search for bug.
Bisect Bugs
❹‣git bisect run mvn test
‣Binary-search for bug.
‣Manual or automated modes.
Bisect Bugs
❹‣git bisect run mvn test
‣Binary-search for bug.
‣Manual or automated modes.
‣Yak cruelty-prevention.
Bisect Bugs
❸‣git merge --squash mybranch
Squash Verbosity
❸‣git merge --squash mybranch
‣Reduce all your micro-checkins to block commits.
Squash Verbosity
❸‣git merge --squash mybranch
‣Reduce all your micro-checkins to block commits.
‣Make mistakes, revise, checkin without hesitation.
Squash Verbosity
❸‣git merge --squash mybranch
‣Reduce all your micro-checkins to block commits.
‣Make mistakes, revise, checkin without hesitation.
‣Great for SVN compatibility.
Squash Verbosity
❷‣git grep SomeText HEAD^^^
Search History
❷‣git grep SomeText HEAD^^^
‣Search in file history without checkout.
Search History
❷‣git grep SomeText HEAD^^^
‣Search in file history without checkout.
‣Greps contents.
Search History
❶‣git rebase master
Rebase
❶‣git rebase master
‣Reposition your feature branch’s start point.
Rebase
❶‣git rebase master
‣Reposition your feature branch’s start point.
‣Makes for simpler merge graphs.
Rebase
❶‣git rebase master
‣Reposition your feature branch’s start point.
‣Makes for simpler merge graphs.
‣Sustains feature-branch work clarity.
Rebase
Tomorrow’s VCS, Today
MatthewTwitter @matthewmccull
Blog http://www.ambientideas.com/blog sidebar has all my social media links
Email [email protected]
GitHub http://github.com/matthewmccullough
Git Homepagehttp://git-scm.com
Directed Acrylic Graphhttp://en.wikipedia.org/wiki/Directed_acyclic_graph
Git for Computer Scientistshttp://eagain.net/articles/git-for-computer-scientists/
Git Treeishhttp://book.git-scm.com/4_git_treeishes.html
Resources
Git Docshttp://www.kernel.org/pub/software/scm/git/docs/
Git Magic eBookhttp://www-cs-students.stanford.edu/~blynn/gitmagic/book.pdf
Linus Torvald’s Git talk at Googlehttp://www.youtube.com/watch?v=4XpnKHJAok8
CygWinhttp://www.cygwin.com
Resources
MSysGithttp://code.google.com/p/msysgit
Git Cheetahhttp://code.google.com/p/msysgit/wiki/GitCheetah
Matthew’s Git Bookmarkshttp://delicious.com/matthew.mccullough/git
Matthew’s Bash Prompthttp://gist.github.com/47267
Resources
‣ http://www.ambientideasphotography.com‣ http://flickr.com/photos/lenore-m/2903856664/‣ http://en.wikipedia.org/wiki/Git_(software)‣ http://flickr.com/photos/karenhorton/1583513014/‣ http://flickr.com/photos/mashdnart/2545782407/‣ http://commons.wikimedia.org/wiki/
File:Small_Boy_nuclear_test_1962.jpg‣ http://www.flickr.com/photos/knmurphy/2506896257/‣ http://www.flickr.com/photos/albyspace/1022035568/‣ http://flickr.com/photos/michaelhays/3070238360/‣ http://flickr.com/photos/d_vdm/509996632/
Image Credits