SlideShare a Scribd company logo
1 of 34
Git
“The stupid content tracker”
What is Git?

A  popular distributed version control
 system designed to handle very large
 projects with speed and efficiency.
http://git-scm.com/
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)             * Cygwin is a bit slower

    CVS                      1.7 GB
    SVN                      3.9 GB
    GIT                      511 MB
Git History
2002
 ◦ 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
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 fast
 Easy   branching & merging
  ◦ Each commit can have multiple parents.
 Cleaner
  ◦ Everything is stored in a single top-level .git directory
Centralized vs.
Decentralized
Centralized SCM




                                     Source: http://is.gd/dBd6R
•Operations require central server
  •Single point of failure
  •Can be a bottleneck
Decentralized SCM




                                        Source: http://is.gd/dBd6R



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




                                Source: http://is.gd/dBd6R


Clone from a remote upstream repository
Decentralized Example




                                 Source: http://is.gd/dBd6R


Create topic branches based on the
pristine copy
Decentralized Example




                                Source: http://is.gd/dBd6R


Push both branches back to upstream
Decentralized Example




                                 Source: http://is.gd/dBd6R


Push changes to another web server
Decentralized Example




                                  Source: http://is.gd/dBd6R


Push & Pull changes from another co-
worker, or back to the web server
Benefits of Decentralization
Commit       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_idea
No  single point of failure
Trivial backups
Fast operations*
Look familiar?
$ git status          $ svn status
$ git diff            $ svn diff | less
$ git log             $ svn log | less
$ git blame           $ svn blame
*
  $ git add FILE      $ svn add FILE
$ git rm FILE         $ svn rm FILE
$ git mv FILE         $ svn mv FILE
*
  $ git revert FILE   $ svn revert FILE
Ok…

So what’s different?
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
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/add
Don’t   like the index?
 ◦ $ git commit -a
 ◦ Automatically stages deleted/modified files
 ◦ Still must use git add to add new ones
   (just like SVN)
Some different commands
$ git commit -a     $ svn commit
$ git clone url     $ svn checkout url
$ git pull          $ svn update
$ git remote

$ git tag -a name   $ svn copy
                      http://repo.com/svn/tr
                      unk
                      http://repo.com/svn/ta
                      gs/name
More different commands
$ git merge branch      $ svn merge -r 20:HEAD
                          http://example.com/sv
                          n/branches/branch
$ git rebase onbranch

$ git stash

$ git submodule
Merge 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
Rebasing
What   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 top
Why   do it?
 ◦ Clean up your history
 ◦ Don’t have to leave old topic branches lying
   around
What   to watch out for?
 ◦ Don’t rework your history if you’ve already
   merged and pushed to a remote repo that others
   use
Rebase 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
Stashing files
Why?
  ◦ 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
Help, Git is scary!   (137 Commands)




                           Source: http://is.gd/dBd6R
Most used…   (24 Commands)




                  Source: http://is.gd/dBd6R
Some GUI tools…   (+5 Commands)




                       Source: http://is.gd/dBd6R
The “plumbing”   (most never used)




                      Source: http://is.gd/dBd6R
Ok, so maybe not so 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       Explains all the ways you can refer to
                                     things
Command             help
 ◦   $ git help foo
                                                   $    git help
 ◦   $ man git-foo              man pages

 ◦   $ git foo --help
 ◦   $ git foo -h               brief help
Subversion 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
Subversion 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
Other resources
Crash   course for SVN users
  ◦ http://git.or.cz/course/svn.html
Cheat   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/
Quick Demo
Questions?

More Related Content

What's hot

Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeDanielle Madeley
 
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and ChefScaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chefbridgetkromhout
 
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012Gosuke Miyashita
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochranedotCloud
 
GIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APPGIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APPPavel Tyk
 
Inside Sqale's Backend at RubyConf Taiwan 2012
Inside Sqale's Backend at RubyConf Taiwan 2012Inside Sqale's Backend at RubyConf Taiwan 2012
Inside Sqale's Backend at RubyConf Taiwan 2012Gosuke Miyashita
 
Inside Sqale's Backend at YAPC::Asia Tokyo 2012
Inside Sqale's Backend at YAPC::Asia Tokyo 2012Inside Sqale's Backend at YAPC::Asia Tokyo 2012
Inside Sqale's Backend at YAPC::Asia Tokyo 2012Gosuke Miyashita
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Consuming Cinder from Docker
Consuming Cinder from DockerConsuming Cinder from Docker
Consuming Cinder from DockerJohn Griffith
 
Deep dark-side of git: How git works internally
Deep dark-side of git: How git works internallyDeep dark-side of git: How git works internally
Deep dark-side of git: How git works internallySeongJae Park
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
TIAD 2016 : Migrating 100% of your production services to containers
TIAD 2016 : Migrating 100% of your production services to containersTIAD 2016 : Migrating 100% of your production services to containers
TIAD 2016 : Migrating 100% of your production services to containersThe Incredible Automation Day
 

What's hot (20)

Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Git Heaven with Wakanda
Git Heaven with WakandaGit Heaven with Wakanda
Git Heaven with Wakanda
 
Docker up and running
Docker up and runningDocker up and running
Docker up and running
 
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and ChefScaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
 
Django via Docker
Django via DockerDjango via Docker
Django via Docker
 
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken Cochrane
 
GIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APPGIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APP
 
Inside Sqale's Backend at RubyConf Taiwan 2012
Inside Sqale's Backend at RubyConf Taiwan 2012Inside Sqale's Backend at RubyConf Taiwan 2012
Inside Sqale's Backend at RubyConf Taiwan 2012
 
Inside Sqale's Backend at YAPC::Asia Tokyo 2012
Inside Sqale's Backend at YAPC::Asia Tokyo 2012Inside Sqale's Backend at YAPC::Asia Tokyo 2012
Inside Sqale's Backend at YAPC::Asia Tokyo 2012
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Consuming Cinder from Docker
Consuming Cinder from DockerConsuming Cinder from Docker
Consuming Cinder from Docker
 
Deep dark-side of git: How git works internally
Deep dark-side of git: How git works internallyDeep dark-side of git: How git works internally
Deep dark-side of git: How git works internally
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
 
TIAD 2016 : Migrating 100% of your production services to containers
TIAD 2016 : Migrating 100% of your production services to containersTIAD 2016 : Migrating 100% of your production services to containers
TIAD 2016 : Migrating 100% of your production services to containers
 

Similar to Git presentation

Similar to Git presentation (20)

Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git
GitGit
Git
 
Git: Why And How to
Git: Why And How toGit: Why And How to
Git: Why And How to
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
 
Git101
Git101Git101
Git101
 
Git basics
Git basicsGit basics
Git basics
 
Why Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysWhy Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anyways
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Git
GitGit
Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 

Git presentation

  • 2. What is Git? A popular distributed version control system designed to handle very large projects with speed and efficiency. http://git-scm.com/
  • 3. 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) * Cygwin is a bit slower CVS 1.7 GB SVN 3.9 GB GIT 511 MB
  • 4. Git History 2002 ◦ 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
  • 5. 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 fast  Easy branching & merging ◦ Each commit can have multiple parents.  Cleaner ◦ Everything is stored in a single top-level .git directory
  • 7. Centralized SCM Source: http://is.gd/dBd6R •Operations require central server •Single point of failure •Can be a bottleneck
  • 8. Decentralized SCM Source: http://is.gd/dBd6R •Anyone can be a server •Everyone has a full local repository
  • 9. Decentralized Example Source: http://is.gd/dBd6R Clone from a remote upstream repository
  • 10. Decentralized Example Source: http://is.gd/dBd6R Create topic branches based on the pristine copy
  • 11. Decentralized Example Source: http://is.gd/dBd6R Push both branches back to upstream
  • 12. Decentralized Example Source: http://is.gd/dBd6R Push changes to another web server
  • 13. Decentralized Example Source: http://is.gd/dBd6R Push & Pull changes from another co- worker, or back to the web server
  • 14. Benefits of Decentralization Commit 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_idea No single point of failure Trivial backups Fast operations*
  • 15. Look familiar? $ git status $ svn status $ git diff $ svn diff | less $ git log $ svn log | less $ git blame $ svn blame * $ git add FILE $ svn add FILE $ git rm FILE $ svn rm FILE $ git mv FILE $ svn mv FILE * $ git revert FILE $ svn revert FILE
  • 17. 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
  • 18. 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/add Don’t like the index? ◦ $ git commit -a ◦ Automatically stages deleted/modified files ◦ Still must use git add to add new ones (just like SVN)
  • 19. Some different commands $ git commit -a $ svn commit $ git clone url $ svn checkout url $ git pull $ svn update $ git remote $ git tag -a name $ svn copy http://repo.com/svn/tr unk http://repo.com/svn/ta gs/name
  • 20. More different commands $ git merge branch $ svn merge -r 20:HEAD http://example.com/sv n/branches/branch $ git rebase onbranch $ git stash $ git submodule
  • 21. Merge 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
  • 22. Rebasing What 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 top Why do it? ◦ Clean up your history ◦ Don’t have to leave old topic branches lying around What to watch out for? ◦ Don’t rework your history if you’ve already merged and pushed to a remote repo that others use
  • 23. Rebase 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
  • 24. Stashing files Why? ◦ 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
  • 25. Help, Git is scary! (137 Commands) Source: http://is.gd/dBd6R
  • 26. Most used… (24 Commands) Source: http://is.gd/dBd6R
  • 27. Some GUI tools… (+5 Commands) Source: http://is.gd/dBd6R
  • 28. The “plumbing” (most never used) Source: http://is.gd/dBd6R
  • 29. Ok, so maybe not so 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 Explains all the ways you can refer to things Command help ◦ $ git help foo $ git help ◦ $ man git-foo man pages ◦ $ git foo --help ◦ $ git foo -h brief help
  • 30. Subversion 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
  • 31. Subversion 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
  • 32. Other resources Crash course for SVN users ◦ http://git.or.cz/course/svn.html Cheat 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/

Editor's Notes

  1. 70-80% smaller than CVS & SVN
  2. SHA1 was used by design due to the distributed nature of git. ie: “Your revision X != my revision X”. Because SHA1 is used, commits can now easily be cryptographically secured & signed by tagging them.
  3. All history is stored in a central location To get a simple log for a project with a lot of commits can take a while
  4. Obviously, this is a great benefit for developing a large project like the kernel
  5. Since branching is so easy, creating & merging branches to fix a single bug or add a single new feature becomes very common.