Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

jnewland.com/tag/git

Slide 3

Slide 3 text

What is Git? • A popular distributed version control system designed to handle very large projects with speed and efficiency. • http://git.or.cz/

Slide 4

Slide 4 text

quick survey • Who is not using source control? • SVN? • CVS? (still?)

Slide 5

Slide 5 text

• Written by Linus Torvalds • Written to manage the Linux Kernel Git History

Slide 6

Slide 6 text

Getting Git

Slide 7

Slide 7 text

For the brave # install gnupg, gettext $ curl -O http://kernel.org/pub/software/scm/git/ git-1.5.4.1.tar.gz $ tar xzf git-1.5.4.1.tar.gz $ ./configure $ make $ sudo make install $ curl http://www.kernel.org/pub/software/scm/git/git- manpages-1.5.4.tar.bz2 $ sudo tar xjf git-manpages-1.5.4.tar.bz2 -C /usr/ local/share/man

Slide 8

Slide 8 text

For the weak sudo port install git-core +svn sudo apt-get install git-core sudo yum install git-core

Slide 9

Slide 9 text

Initial Setup $ git config --global user.name='My Name' $ git config --global user.email=me@mydomain.net # optional, for pretty colors $ git config --global color.diff=auto $ git config --global color.diff.new=cyan $ git config --global color.diff.old=magenta $ git config --global color.diff.frag=yellow $ git config --global color.diff.meta=green $ git config --global color.diff.commit=normal

Slide 10

Slide 10 text

Why Git? • Distributed, not Centralized • Revolutionizes how you use branching • Extremely stupidly ridiculously fast, even with large projects • Community

Slide 11

Slide 11 text

Centralized vs Distributed

Slide 12

Slide 12 text

Centralized VCS • Repository • History stored in central location • Checkout • A ‘working tree’

Slide 13

Slide 13 text

Distributed VCS • Every Git working directory is a full-fledged repository with full revision tracking capabilities, not dependent on network access or a central server. • Commits happen offline. • Commits can then be pushed and pulled between repositories with shared history.

Slide 14

Slide 14 text

Wait, commits happen offline?

Slide 15

Slide 15 text

Commits happen offline!!!!!!!11!!!

Slide 16

Slide 16 text

on the plane

Slide 17

Slide 17 text

on the train

Slide 18

Slide 18 text

at that crappy coffee shop with the paid WiFi

Slide 19

Slide 19 text

at an ATLRUG meeting

Slide 20

Slide 20 text

Branching FTW

Slide 21

Slide 21 text

“But I don’t branch”

Slide 22

Slide 22 text

because you don’t use Git

Slide 23

Slide 23 text

quick survey #2 • How many of you use branching? • Work exclusively on trunk/master? • NEVER work on trunk/master?

Slide 24

Slide 24 text

Why branching with Git is awesome • Instant $ time git checkout -b newbranch Switched to a new branch "newbranch" real 0m0.227s • Private • Merging doesn’t suck

Slide 25

Slide 25 text

Forget about ‘breaking the build’ • ‘Atomic’ commits are a thing of the past • ‘Atomic’ merges

Slide 26

Slide 26 text

• Prototype well-developed changes • Commit early and often • Review and revise before you merge Topic Branches

Slide 27

Slide 27 text

With Git, branches are now a part of my everyday workflow

Slide 28

Slide 28 text

‘Tomorrow’ branch

Slide 29

Slide 29 text

‘Drunk’ branch

Slide 30

Slide 30 text

Performance

Slide 31

Slide 31 text

Offline Operations • Performing a diff • Viewing file history • Committing changes • Merging branches • Obtaining any other revision of a file • Switching branches

Slide 32

Slide 32 text

Online operations are fast too $ time svn co http://svn.rubyonrails.org/rails/ trunk/ ... real 0m29.537s

Slide 33

Slide 33 text

Online operations are fast too $ time git clone --depth 1 git://github.com/josh/ rails.git ... real 0m9.088s

Slide 34

Slide 34 text

Online operations are fast too $ time git clone git://github.com/josh/rails.git ... real 0m37.512s

Slide 35

Slide 35 text

Git for Subversion Users

Slide 36

Slide 36 text

This looks familiar $ git status $ git log $ git blame $ git add FILE $ git rm FILE $ git mv FILE $ svn status $ svn log $ svn blame $ git add FILE $ git rm FILE $ git mv FILE

Slide 37

Slide 37 text

Creating a Repo $ pwd ~/src/foo $ git init $ git add . $ git commit

Slide 38

Slide 38 text

Checking out a Repo $ git clone REPO_URL

Slide 39

Slide 39 text

git status • Untracked Files • Brand new file • Changed but not updated • Locally changed file not in the index • Changes to be committed • ‘The Index’

Slide 40

Slide 40 text

The Index • Staging area for your next commit • Sort of like files marked A, M, D in svn status output

Slide 41

Slide 41 text

One major difference • After making any changes to the working directory, and before running the commit command, you must use the add command to add any new or modified files to the index.

Slide 42

Slide 42 text

Example # create bar and to the index echo “foo” > bar git add bar # change bar, and thus remove from the index echo “ “ >> bar # add bar to the index again git add bar

Slide 43

Slide 43 text

Committing • git commit • commit what’s in the index • git commit -a • adds changed but not untracked files to the index, then commits • exactly like SVN

Slide 44

Slide 44 text

Diffs # diff between working tree and the index $ git diff # diff between the index and last commit $ git diff --cached # diff between working tree and last commit $ git diff HEAD

Slide 45

Slide 45 text

Logs # just like svn $ git log # find a commit changed a specific string $ git log -S"def stupid_method" # log with patches for each commit $ git log -p

Slide 46

Slide 46 text

Reverting Changes $ git checkout PATH $ svn revert PATH

Slide 47

Slide 47 text

git revert != svn revert # most similar to svn revert $ git checkout . # reverse commit and commit the result $ git revert

Slide 48

Slide 48 text

Branching # create a new branch $ git branch NEW_BRANCH # switch to this branch $ git checkout NEW_BRANCH # create a new branch and check it out in one step $ git checkout -b NEW_BRANCH

Slide 49

Slide 49 text

More Branching # view available branches $ git branch * new_branch master # delete a branch $ git branch -d ALREADY_MERGED_BRANCH $ git branch -D BAD_BRANCH

Slide 50

Slide 50 text

Diffing and Logging with Branches # log of changes to other_branch not in master $ git log NEW_BRANCH..master # diff of those changes $ git diff NEW_BRANCH..master

Slide 51

Slide 51 text

Merging # get back to the master $ git checkout master # merge in changes from your other branch $ git merge NEW_BRANCH # optionally, delete the branch $ git branch -d NEW_BRANCH

Slide 52

Slide 52 text

Rebasing # store local changes not in BRANCH_NAME as patches, updates the local branch to BRANCH_NAME, then applies the patches $ git rebase BRANCH_NAME

Slide 53

Slide 53 text

Danger, Will Robinson • Rebase is dangerous • Rewrites commit history • Don’t use on a branch you’re sharing

Slide 54

Slide 54 text

Oh noes! Merge Conflicts!

Slide 55

Slide 55 text

Easy Conflict Resolution $ git merge conflict_branch Auto-merged README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. # fix conflict then commit $ vim README $ git add README $ git commit -m “fixed merge conflict”

Slide 56

Slide 56 text

Collaboration with GIT

Slide 57

Slide 57 text

Hosting a Git Repo • git-daemon • gitosis

Slide 58

Slide 58 text

Hosting a Git Repo • git-daemon • gitosis

Slide 59

Slide 59 text

github.com

Slide 60

Slide 60 text

Fork your friends

Slide 61

Slide 61 text

‘MySpace for hackers’

Slide 62

Slide 62 text

Track forks of your repository

Slide 63

Slide 63 text

Free for public repos

Slide 64

Slide 64 text

• Still in beta • Email me at jnewland@gmail.com if you’d like an invite (20 left)

Slide 65

Slide 65 text

Common Use Cases • Contributor • Create Patches • Send Patches • Maintainer • Review Patches • Apply Patches

Slide 66

Slide 66 text

Contributor

Slide 67

Slide 67 text

Fork, then clone • Fork repo at github http://github.com/jnewland/atlrug-demo/tree/master • Clone your copy of my repo $ git clone git@github.com/USERNAME/atlrug-demo.git

Slide 68

Slide 68 text

Make changes $ git checkout -b my_branch $ echo “hello again” >> README $ git commit -a

Slide 69

Slide 69 text

Track the upstream # add a remote $ git remote add jnewland git://github.com/ jnewland/atlrug-demo.git # add a branch $ git checkout -b jnewland/master # update the tracking branch $ git pull jnewland master

Slide 70

Slide 70 text

Merge it all together # switch back to the master $ git checkout master # update master with your changes $ git merge my_branch # update master with upstream changes $ git merge jnewland/master

Slide 71

Slide 71 text

Push it real good $ git push origin master

Slide 72

Slide 72 text

Sending Patches • Old skool: $ git format-patch jnewland • New hotness - ‘Pull Request’

Slide 73

Slide 73 text

No more emailing patches

Slide 74

Slide 74 text

No more emailing patches

Slide 75

Slide 75 text

Maintainer

Slide 76

Slide 76 text

Receive pull request

Slide 77

Slide 77 text

Grab mtodd’s changes # add a remote $ git remote add mtodd git://github.com/mtodd/ atlrug-demo.git # add a branch $ git checkout -b mtodd/master # pull the changes $ git pull mtodd master

Slide 78

Slide 78 text

Merge, then push! # switch back to master $ git checkout master # merge $ git merge mtodd/master # push $ git push

Slide 79

Slide 79 text

SVN Integration

Slide 80

Slide 80 text

“the best part about GIT is that no one has to know you’re using it”

Slide 81

Slide 81 text

basic git-svn workflow $ git svn clone REPO_URL # ... hack hack hack ... $ git commit -a # ... hack hack hack ... $ git commit -a $ git svn rebase $ git svn dcommit

Slide 82

Slide 82 text

better workflow $ git svn clone REPO_URL $ git checkout -b new_branch # ... hack hack hack ... $ git commit -a $ git svn rebase $ git svn dcommit $ git checkout master $ git branch -d new_branch $ git svn rebase

Slide 83

Slide 83 text

Pretty GUIs

Slide 84

Slide 84 text

gitk • Bundled with git • Excellent visualization of branching history

Slide 85

Slide 85 text

GitNub • http://github.com/Caged/ gitnub/tree/master • RubyCocoa

Slide 86

Slide 86 text

More Resources • http://git.or.cz/ • http://cheat.errtheblog.com/s/git/ • http://github.com/guides • #git and #github on irc.freenode.org

Slide 87

Slide 87 text

Questions? Comments? Flames?

Slide 88

Slide 88 text

Jesse Newland jnewland@gmail.com http://jnewland.com

Slide 89

Slide 89 text

flickr is awesome • http://flickr.com/photos/alper/528441936/ • http://flickr.com/photos/joan-fabregat/ 1947832858/ • http://flickr.com/photos/feria/2316579746/