105
Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com GIT: An Illustrated Primer

Git, an Illustrated Primer

Embed Size (px)

DESCRIPTION

Given at the July BCSPHP Meeting

Citation preview

Page 1: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

GIT: An Illustrated Primer

Page 2: Git, an Illustrated Primer

http://mojolive.com/profile/dcousineau

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 3: Git, an Illustrated Primer

History

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 4: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

BitKeeper No Longer Free To Use

Linux Kernel RequiresDistributed

Performant

SVN and CVS... Not So Much

“CVS is what we should NOT do...”

Page 5: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

GITthus,

Page 6: Git, an Illustrated Primer

gItting started

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 7: Git, an Illustrated Primer

+Linux

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> sudo apt-get install git$> sudo yum install git$> echo "Seriously?"

Page 8: Git, an Illustrated Primer

+OSX

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

http://git-scm.com

Page 9: Git, an Illustrated Primer

+OSX

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)$> brew install git$> say "Win!"

Page 10: Git, an Illustrated Primer

+Windows

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

http://windows.github.com

Page 11: Git, an Illustrated Primer

+Gitting STarted

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 12: Git, an Illustrated Primer

+My First Repo

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 13: Git, an Illustrated Primer

+Stage New Files

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 14: Git, an Illustrated Primer

+Commit Staging

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 15: Git, an Illustrated Primer

+staging?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

working directory

index

repository

Page 16: Git, an Illustrated Primer

+staging?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

working directory

index

repository

“staging”

Page 17: Git, an Illustrated Primer

+staging?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

working directory

index

repository

modify

Page 18: Git, an Illustrated Primer

+staging?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

working directory

index

repository

git add

Page 19: Git, an Illustrated Primer

+staging?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

working directory

index

repository git commit

Page 20: Git, an Illustrated Primer

+Directories

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 21: Git, an Illustrated Primer

+Modify

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 22: Git, an Illustrated Primer

+Branch!

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 23: Git, an Illustrated Primer

+Back to Master

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 24: Git, an Illustrated Primer

+Merge!

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 25: Git, an Illustrated Primer

+stashing

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 26: Git, an Illustrated Primer

+Popping

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 27: Git, an Illustrated Primer

branching

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 28: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

a b c

MASTER

HEAD

Page 29: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

a b c

MASTER

DEVELOP

create new branch

HEAD

Page 30: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

a b c

MASTER

DEVELOP

Checkout new branch

HEAD

Page 31: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

a b c

MASTER

DEVELOP

commit to develop

d

HEAD

Page 32: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

commit to master HEAD

a b c

MASTER

DEVELOP

d

e

Page 33: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

a b c

MASTER

DEVELOP

merge Develop

d

e

f

Page 34: Git, an Illustrated Primer

Remote

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 35: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

SVN GIT

d

e

b

a

c

d

e

b

a

c

d d

e

b

a

c

Page 36: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 37: Git, an Illustrated Primer

+Create a Project

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 38: Git, an Illustrated Primer

+Create a Project

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 39: Git, an Illustrated Primer

+Doing as I am told

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 40: Git, an Illustrated Primer

+did as I was told

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 41: Git, an Illustrated Primer

+Push Again!

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 42: Git, an Illustrated Primer

+Fetching & Merging

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 43: Git, an Illustrated Primer

+Pulling

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 44: Git, an Illustrated Primer

+Two Authors Two Pushes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 45: Git, an Illustrated Primer

+Two Authors Two Pushes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 46: Git, an Illustrated Primer

+AFtermath

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 47: Git, an Illustrated Primer

+Aftermath

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 48: Git, an Illustrated Primer

+Aftermath

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 49: Git, an Illustrated Primer

+AFtermath

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 50: Git, an Illustrated Primer

+forking

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 51: Git, an Illustrated Primer

+pull requests

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 52: Git, an Illustrated Primer

+MAke Changes IN A NEW BRANCH

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 53: Git, an Illustrated Primer

+Push Changes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 54: Git, an Illustrated Primer

+See Our New Branch

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 55: Git, an Illustrated Primer

+Create Pull Request

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 56: Git, an Illustrated Primer

+Oh Look, Our Pull Request

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 57: Git, an Illustrated Primer

+Oh Look Our Pull Request

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 58: Git, an Illustrated Primer

+Oh Look, It’s Merged In!

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 59: Git, an Illustrated Primer

+Remotes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 60: Git, an Illustrated Primer

+Adding Another Remote

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 61: Git, an Illustrated Primer

+create and sync new branches

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 62: Git, an Illustrated Primer

+Delete local and remote branches

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 63: Git, an Illustrated Primer

+Pull From One, Push To Another

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 64: Git, an Illustrated Primer

GIT FLow

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 65: Git, an Illustrated Primer

htt

p://

nv

ie.c

om

/po

sts/

a-

suc

ce

ssfu

l-g

it-

br

an

ch

ing

-m

od

el/

Page 66: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 67: Git, an Illustrated Primer

Subversion and GIT

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 68: Git, an Illustrated Primer

+et voilà

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git svn clone -s -r 1000:HEAD https://url/to/repo ./wkngcpy$> git svn show-ignore > .gitignore

Page 69: Git, an Illustrated Primer

+Workflow

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Normal GIT Workflow

Page 70: Git, an Illustrated Primer

+Sync

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git svn dcommit --dry-run$> git svn dcommit$> git svn rebase

Page 71: Git, an Illustrated Primer

+With some caveats

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

anything that has been dcommit’d

is set in stone! do. not. touch.

git branches wellsvn... not so much

Page 72: Git, an Illustrated Primer

+Local Branching

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git merge --squash branch

Page 73: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

git merge --squash localbrn

HEAD

a b

c

MASTER

localbrn

d e

Page 74: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

git merge --squash localbrn

HEAD

a b

MASTER

DEC

Page 75: Git, an Illustrated Primer

+Why?

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

SVN is TERRIBLE at merges

git-svn will do it if you don’tand when it fails, it does so spectacularly

you’ll just litter your commit history

Page 76: Git, an Illustrated Primer

+tracking svn branches

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git checkout -t remotes/branchname

Page 77: Git, an Illustrated Primer

+creating remote branches

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git svn branch -m “Creating new branch” branchname$> git checkout -t remotes/branchname

Page 78: Git, an Illustrated Primer

+personal opinion

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

except for release taggingand a develop branch

don’t bother with remote branchingjust stick to local and squashes

Page 79: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

use git svn locally

push for team

adoption

procure git server

full clone push to new

git server

Page 80: Git, an Illustrated Primer

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

use git svn locally

push for team

adoption

procure git server

full clone push to new

git server

Page 81: Git, an Illustrated Primer

Advanced Usage

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 82: Git, an Illustrated Primer

+reset my local changes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git checkout -- .

tell git “no more options!”

Page 83: Git, an Illustrated Primer

+Replay Last commit

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git reset --mixed REF

Page 84: Git, an Illustrated Primer

+Gitting Ready

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 85: Git, an Illustrated Primer

+Results

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 86: Git, an Illustrated Primer

+Undo Last commit

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git reset --hard HEAD^

HEAD^ means commit prior to HEAD. HEAD^2 is 2

commits prior, etc etc.

Page 87: Git, an Illustrated Primer

+“Oops i forgot to branch”

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git branch newbranchname$> git reset --hard SHA

commit immediately before the intended first commit

of our new branch

Page 88: Git, an Illustrated Primer

+“Oops i forgot to branch”

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 89: Git, an Illustrated Primer

+“Oops i forgot to branch”

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 90: Git, an Illustrated Primer

+“Oops I accidentally the commit message”

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git rebase --interactive SHA

commit immediately preceding the commit in

question

Page 91: Git, an Illustrated Primer

+Oops

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 92: Git, an Illustrated Primer

+Lay of the land

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 93: Git, an Illustrated Primer

+Making decisions

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 94: Git, an Illustrated Primer

+Reach 88MPH

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 95: Git, an Illustrated Primer

+Fun with Paradoxes

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 96: Git, an Illustrated Primer

+Fruits of our labor

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 97: Git, an Illustrated Primer

+“Oops I committed the private key”

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

$> git filter-branch --index-filter \ 'git rm --cached --ignore-unmatch secret.key' \ --prune-empty --tag-name-filter cat -- --all

ಠ_ಠ

Page 98: Git, an Illustrated Primer

+Terrible Mistake

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 99: Git, an Illustrated Primer

+gone now, here yesterday

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 100: Git, an Illustrated Primer

+VooDoo Magic

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 101: Git, an Illustrated Primer

+Results

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 102: Git, an Illustrated Primer

+Cleanup The Mess

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 103: Git, an Illustrated Primer

+Look Ma, No secret.key!

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 104: Git, an Illustrated Primer

THANKS. FOR YOUR ATTENTION

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

Page 105: Git, an Illustrated Primer

+further resources

Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

http://git-scm.com/book

FREE!Attribution-NonCommercial-ShareAlike 3.0 Unported

https://help.github.com