git presentation

34
Git Git “The stupid content tracker”

Upload: james-cuzella

Post on 15-Jan-2015

239 views

Category:

Documents


1 download

DESCRIPTION

An introduction to the git SCM tool. Geared towards SVN users too.

TRANSCRIPT

Page 1: Git presentation

GitGit“The stupid content tracker”

Page 2: Git presentation

What is Git?What is Git?

A popular distributed version control system designed to handle very large projects with speed and efficiency.

http://git-scm.com/

Page 3: Git presentation

Why is it stupid?Why is it stupid?It’s stupidly fast*

It’s stupidly easy to branch & merge

$ time git checkout -b newbranch

Switched to a new branch 'newbranch'

real 0m0.292s

• Repositories are stupidly small

(size of FreeBSD repo)

CVS 1.7 GB

SVN 3.9 GB

GIT 511 MB

* Cygwin is a bit slower

Page 4: Git presentation

Git HistoryGit History2002

◦Linus uses BitKeeper to track the Linux kernel

April, 2005◦BitMover drops free license for BitKeeper◦Linus starts writing his own SCM: Git

June 2005◦Git is officially used to track the kernel

2007◦Git 1.5.0 released◦Major usability improvement

Page 5: Git presentation

What makes Git better?What makes Git better? It’s distributed!Does not store deltas

◦ Uses SHA1 to uniquely identify a commit◦ Linus called it “a content- addressable

filesystem, used to track directory trees.”Efficiency

◦ Compresses repository very well◦ Local operations are fast◦ Online operations over git:// protocol are also

fastEasy branching & merging

◦ Each commit can have multiple parents.Cleaner

◦ Everything is stored in a single top-level .git directory

Page 6: Git presentation

Centralized vs. Centralized vs. DecentralizedDecentralized

Page 7: Git presentation

Centralized SCMCentralized SCM

•Operations require central server

•Single point of failure•Can be a bottleneck

Source: http://is.gd/dBd6R

Page 8: Git presentation

Decentralized SCMDecentralized SCM

•Anyone can be a server•Everyone has a full local repository

Source: http://is.gd/dBd6R

Page 9: Git presentation

Decentralized ExampleDecentralized Example

Clone from a remote upstream repository

Source: http://is.gd/dBd6R

Page 10: Git presentation

Decentralized ExampleDecentralized Example

Create topic branches based on the pristine copy

Source: http://is.gd/dBd6R

Page 11: Git presentation

Decentralized ExampleDecentralized Example

Push both branches back to upstream

Source: http://is.gd/dBd6R

Page 12: Git presentation

Decentralized ExampleDecentralized Example

Push changes to another web server

Source: http://is.gd/dBd6R

Page 13: Git presentation

Decentralized ExampleDecentralized Example

Push & Pull changes from another co-worker, or back to the web server

Source: http://is.gd/dBd6R

Page 14: Git presentation

Benefits of Benefits of DecentralizationDecentralizationCommit locally

◦Keep experimental code local◦Push solid working code to main repo◦Use local topic branches◦Some idea turns out badly?

$ git branch –d my_bad_ideaNo single point of failureTrivial backupsFast operations*

Page 15: Git presentation

Look familiar?Look familiar?

$ git status$ git diff$ git log$ git blame*$ git add FILE$ git rm FILE$ git mv FILE*$ git revert FILE

$ svn status$ svn diff | less$ svn log | less$ svn blame$ svn add FILE$ svn rm FILE$ svn mv FILE$ svn revert FILE

Page 16: Git presentation

So what’s different?So what’s different?Ok…

Page 17: Git presentation

The Index (Staging area)The Index (Staging area)Never have to fully commit to every

commit◦Decide exactly what you want to commit◦Group changes logically to match up with

your commit message, different topic branches, etc…

◦Stash non-staged code to test before your commit $ git add working_file.c

$ git stash --keep-index(test… commit)git stash pop

Page 18: Git presentation

The Index (Staging area)The Index (Staging area)Good for merging

◦Non-conflicting hunks are auto-staged◦Doesn’t clutter the diff with successfully

merged code Use `git diff –cached` to see what you’re

going to commit◦Only conflicting files left for you to

resolve/addDon’t like the index?

◦$ git commit -a◦Automatically stages deleted/modified

files◦Still must use git add to add new ones

(just like SVN)

Page 19: Git presentation

Some different commandsSome different commands

$ git commit -a$ git clone url$ git pull$ git remote

$ git tag -a name

$ svn commit$ svn checkout url

$ svn update

$ svn copy http://repo.com/svn/trunk http://repo.com/svn/tags/name

Page 20: Git presentation

More different commandsMore different commands

$ git merge branch

$ git rebase onbranch

$ git stash

$ git submodule

$ svn merge -r 20:HEAD http://example.com/svn/branches/branch

Page 21: Git presentation

Merge exampleMerge example$ git checkout branch_tomerge

# Fix a bug$ git commit –a –m ‘fixed a bug’$ git checkout master

# what changed between branches?$ git diff master branch_tomerge$ git merge branch_tomerge

# delete the old branch$ git branch –d branch_tomerge

Page 22: Git presentation

RebasingRebasingWhat is rebasing?

◦Finds all committed changes since you branched

◦Resets your branch so it’s identical to the HEAD of the branch you’re rebasing onto

◦Re-applies your changes on topWhy do it?

◦Clean up your history◦Don’t have to leave old topic branches

lying aroundWhat to watch out for?

◦Don’t rework your history if you’ve already merged and pushed to a remote repo that others use

Page 23: Git presentation

Rebase exampleRebase example# We want to rebase bugfix onto master

$ git checkout bugfix…make changes, and commit here…

# update from remote$ git checkout master$ git pull origin master

# Rebase changes on top of the updated master

$ git checkout bugfix$ git rebase master

# Now we can do a ‘fast-forward’ merge$ git checkout master$ git merge bugfix

Page 24: Git presentation

Stashing filesStashing filesWhy?

◦You’re working on something◦You’ve got some debug code you

don’t want to commit yet◦Need to work on something else

How?◦$ git stash◦Do something else…◦$ git stash pop

Page 25: Git presentation

Help, Git is scary!Help, Git is scary! (137 Commands)(137 Commands)

Source: http://is.gd/dBd6R

Page 26: Git presentation

Most used…Most used… (24 Commands)(24 Commands)

Source: http://is.gd/dBd6R

Page 27: Git presentation

Some GUI tools…Some GUI tools… (+5 Commands)(+5 Commands)

Source: http://is.gd/dBd6R

Page 28: Git presentation

The “plumbing”The “plumbing” (most never used)(most never used)

Source: http://is.gd/dBd6R

Page 29: Git presentation

Ok, so maybe not so Ok, so maybe not so scary…scary…Revision numbers are now SHA1

hashes◦Seems scary, but really isn’t…

Copy/Paste Specify partial hash (868bae) Use references (HEAD^, HEAD^^,

mybranch@{yesterday}) Use tags $ man git-rev-parse

Command help◦$ git help foo◦$ man git-foo◦$ git foo --help◦$ git foo -h

man pages

brief help

$ git help

Explains all the ways you can refer to things

Page 30: Git presentation

Subversion IntegrationSubversion Integration“the best part about GIT is that no

one has to know you’re using it”A 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

Page 31: Git presentation

Subversion IntegrationSubversion Integration“the best part about GIT is that no one has to

know you’re using it”An even better git-svn 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

Page 32: Git presentation

Other resourcesOther resourcesCrash course for SVN users

◦ http://git.or.cz/course/svn.htmlCheat Sheet

◦ http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html

ProGit eBook (Free!)◦ http://progit.org/

Screencasts◦ http://gitcasts.com/

Extremely detailed, yet very helpful presentation◦ http://excess.org/article/2008/07/ogre-git-

tutorial/

Page 33: Git presentation

Quick DemoQuick Demo

Page 34: Git presentation

Questions?Questions?