SlideShare a Scribd company logo
Git
Reuven M. Lerner • reuven@lerner.co.il
       Open Israel Conference
           June 30th, 2011
Who am I?
• Web developer, software architect,
  consultant, lecturer/trainer
• Linux Journal columnist since 1996
• Mostly Ruby on Rails + PostgreSQL, but
  also Python, PHP, jQuery, and lots more...
• Git user (and enthusiast) since 2008
What is
version control?
Time machine

• Return to any point in
  a project’s history
• Find out how files,
  folders have changed
• Learn which user
  made which changes
Backup

• Never fear that you’ve
  deleted a file — just
  rewind the history
• Everything is recorded,
  can be undone
Maintenance tool

• “Tag” releases
• Who is to blame for a particular bug?
• When did we introduce a particular
  problem?
• Deploy specific versions on specific servers
Scratchpad

• Try out new ideas
• Experiment with alternative techniques
• Upgrade a library
• Refactor without affecting the “live” code
  base
Collaboration tool
• Work without fear of
  “stomping” on
  someone else’s code
• Identify conflicts
  between what
  developers wrote
• Mix and match teams
  for projects
Version control is great
• If you’re a programmer and not using
  version control, you’re really missing out
 • It’s also good for non-programs, such as
    configuration files
• If you’re a CTO/team leader/VP R&D and
  your people aren’t using version control,
  you’re inviting disaster
What do people use?
• RCS (ancient history)
• CVS (should be ancient history)
• Subversion (“a better CVS”)
• SourceSafe
• Perforce
• lots of other systems
Problems with these
• Work requires a server connection
 • (You can work, but not commit.)
• Branching and merging is painful and slow
 • So no one does it!
• Enforces a particular workflow
• More code, more developers — slower VC
Distributed version
         control
• Distributed: Everyone is their own server!
• Everyone has a complete commit history
 • No single point of failure
• Commit whenever you want (i.e., often)
• Merge when two repositories connect
Git
• Linus needed a VCS... so he wrote one!
 • Fast
 • Accurate
 • Distributed
 • Massively scalable
 • Super flexible
Open-source Git users
• Linux kernel
• PostgreSQL
• Ruby language
• Ruby on Rails
• Perl language
• among many, many others
Give me details!


• What does Git do that others don’t?
• Why do I claim that Git has changed my
  life?
Branching & merging
• Branching and merging is both easy and fast
  in Git
• I often branch and merge several times in a
  given day
  • When I used SVN, I would do everything
    in my power to avoid branching, because
    merges were long and difficult
Branching & merging
• Create a branch:
 git checkout -b new-branch

• Merge commits from other-branch
 git merge other-branch

• Yes, it’s really that easy.
• You don’t even have to change directories!
Easy branching
   changes everything!
• Every new feature goes in a branch
• Merging becomes easy, fast, and natural
• Side projects are stored, not kept out of
  version control for fear of “contamination”
• Commit, commit, commit all of the time, in
  an appropriate branch — never lose work!
Local repository
         is great
• Work without a network connection
• Commits, merges, and switching branches
  are nearly instantaneous
• Reports and logs are super-fast
 • “Show me all files modified on Tuesday of
    last week” produces immediate resultss
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
Create a repository!
/tmp $ cd myapp
/tmp/myapp $ git init
Initialized empty Git repository in /private/tmp/myapp/.git/
master ✗ /tmp/myapp $ git add .
master ✗ /tmp/myapp $ git commit -a -m 'Initial commit'
[master (root-commit) 030c6b6] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
Initial commit


master ✔ /tmp/myapp $
The result

master ✔ /tmp/myapp $ git log

commit 030c6b691993e0f43d78119d9ff1c9e759120d11
Author: Reuven Lerner <reuven@lerner.co.il>
Date:   Thu Jun 30 12:29:29 2011 +0300
    I
Committing in stages

• You can commit all modified files (“git
  commit -a”)
• You can add files to be committed (“git add
  foo.rb”) over time
• Using the staging area gives you
  tremendous flexibility before committing
Remote branches

• A local branch can “track” a remote branch
• Different branches can be on different
  servers — and then you can merge across
  them
• One possible workflow: Read from one
  remote branch, and write to another
Integration
• Git is all small Unix commands
• Easily integrated into text editors, IDEs,
  cron jobs, monitoring, and system tasks
• Example: Continuous integration servers
• Example: Code-analysis tools
• Also: Front ends to SVN and others!
git blame

• Shows the commit, user, and timestamp of
  when each line of a file was changed
• Useful when you want to know who broke
  the build
• Also useful for deflecting blame from
  clients, who think you broke something!
a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   29)
a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   30) #ifdef WIN32
65e806cb (Bruce Momjian     2010-02-26 02:01:40 +0000   31) #define FD_SETSIZE 1024
a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   32) #endif   /* ! WIN32 */
a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   33)
d08741ea (Tom Lane          2001-02-10 02:31:31 +0000   34) #include "postgres_fe.h"
a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   35)
a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   36) #include "libpq-fe.h"
a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    37) #include "libpq/pqsignal.h"
3da0dfb4 (Tatsuo Ishii      2009-08-03 15:18:14 +0000   38) #include "portability/instr_time.h"
a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   39)
d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   40) #include <ctype.h>
d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   41)
a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    42) #ifndef WIN32
a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   43) #include <sys/time.h>
a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   44) #include <unistd.h>
ffda6747 (Tom Lane          2007-09-27 20:39:43 +0000   45) #endif   /* ! WIN32 */
Commit
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   29)
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   30) #ifdef WIN32
 65e806cb (Bruce Momjian     2010-02-26 02:01:40 +0000   31) #define FD_SETSIZE 1024
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   32) #endif   /* ! WIN32 */
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   33)
 d08741ea (Tom Lane          2001-02-10 02:31:31 +0000   34) #include "postgres_fe.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   35)
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   36) #include "libpq-fe.h"
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    37) #include "libpq/pqsignal.h"
 3da0dfb4 (Tatsuo Ishii      2009-08-03 15:18:14 +0000   38) #include "portability/instr_time.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   39)
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   40) #include <ctype.h>
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   41)
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    42) #ifndef WIN32
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   43) #include <sys/time.h>
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   44) #include <unistd.h>
 ffda6747 (Tom Lane          2007-09-27 20:39:43 +0000   45) #endif   /* ! WIN32 */
Commit User
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   29)
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   30) #ifdef WIN32
 65e806cb (Bruce Momjian     2010-02-26 02:01:40 +0000   31) #define FD_SETSIZE 1024
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   32) #endif   /* ! WIN32 */
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   33)
 d08741ea (Tom Lane          2001-02-10 02:31:31 +0000   34) #include "postgres_fe.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   35)
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   36) #include "libpq-fe.h"
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    37) #include "libpq/pqsignal.h"
 3da0dfb4 (Tatsuo Ishii      2009-08-03 15:18:14 +0000   38) #include "portability/instr_time.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   39)
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   40) #include <ctype.h>
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   41)
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    42) #ifndef WIN32
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   43) #include <sys/time.h>
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   44) #include <unistd.h>
 ffda6747 (Tom Lane          2007-09-27 20:39:43 +0000   45) #endif   /* ! WIN32 */
Commit User                     Timestamp
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   29)
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   30) #ifdef WIN32
 65e806cb (Bruce Momjian     2010-02-26 02:01:40 +0000   31) #define FD_SETSIZE 1024
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   32) #endif   /* ! WIN32 */
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   33)
 d08741ea (Tom Lane          2001-02-10 02:31:31 +0000   34) #include "postgres_fe.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   35)
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   36) #include "libpq-fe.h"
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    37) #include "libpq/pqsignal.h"
 3da0dfb4 (Tatsuo Ishii      2009-08-03 15:18:14 +0000   38) #include "portability/instr_time.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   39)
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   40) #include <ctype.h>
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   41)
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    42) #ifndef WIN32
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   43) #include <sys/time.h>
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   44) #include <unistd.h>
 ffda6747 (Tom Lane          2007-09-27 20:39:43 +0000   45) #endif   /* ! WIN32 */
Commit User                     Timestamp                 Line # and code
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   29)
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   30) #ifdef WIN32
 65e806cb (Bruce Momjian     2010-02-26 02:01:40 +0000   31) #define FD_SETSIZE 1024
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   32) #endif   /* ! WIN32 */
 a23c6415 (Magnus Hagander   2009-07-30 09:28:00 +0000   33)
 d08741ea (Tom Lane          2001-02-10 02:31:31 +0000   34) #include "postgres_fe.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   35)
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   36) #include "libpq-fe.h"
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    37) #include "libpq/pqsignal.h"
 3da0dfb4 (Tatsuo Ishii      2009-08-03 15:18:14 +0000   38) #include "portability/instr_time.h"
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   39)
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   40) #include <ctype.h>
 d156e1f8 (Tom Lane          2005-10-07 15:34:17 +0000   41)
 a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000    42) #ifndef WIN32
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   43) #include <sys/time.h>
 a765db40 (Tatsuo Ishii      2000-01-15 12:38:09 +0000   44) #include <unistd.h>
 ffda6747 (Tom Lane          2007-09-27 20:39:43 +0000   45) #endif   /* ! WIN32 */
git bisect
• You introduced a bug, but don’t know
  where? Git can find it!
 • Give two endpoints
 • Git does a binary search between them
 • For each commit, tell Git whether it is
    “good” or “bad”
 • This finds the bug very quickly
Stash
• Temporary storage space
• Useful if you have done enough work to
  keep, but not enough for a commit
• Emergency fixes in the middle of working
  on something else
• If you need, put the stash into a new branch
• Oh, you can have multiple stashes
Hooks
• Execute arbitrary code when things happen
• Example: Update submodules automatically
• Example: Send e-mail after a commit
• Example: Heroku uses hooks to deploy a
  new version of your Web app when you
  push to them!
Workflows

• Git supports many, many workflows
 • Traditional centralized server
 • BDFL and users
 • BDFL and Lieutenants
• Do what works for you!
Traditional




Source: ProGit.org
Integration-manager




Source: ProGit.org
Large, BDFL




Source: ProGit.org
Cherry picking

• You can merge specific
  commits, or parts of
  commits
• Amazingly powerful
Rebase
• An alternative to regular merging
• First merge all external commits, then
  replay your changes on top
• Helps to keep you aligned with remote
  branches
• Avoids some merge-conflict issues
Submodules

• A Git repository can point to other
  repositories — submodules
• Break a project into smaller projects
• Git puts the pieces together for you!
Amending commits
• Commits are not sacred in Git
• Rather, they are a tool to manage history
• Change, amend, and edit commits
• Yes, this can be dangerous!
• Also avoids hundreds of “fixed typo”
  commits in a row...
Commercial hosting

• You can host Git repositories on your own
• Want to go commercial? GitHub,
  Gitorious, and many others work great
• GitHub is free for open-source projects,
  and thus very popular
Git talk from Open 2011 conference in Israel
GUIs

• Yes, there are now GUIs for Git
• Windows, Mac, and Unix versions all exist
• Integration with Emacs and other editors
  for hard-core hacker-nerds
• Also: Shell-prompt integration for Unix
In short
• Git has completely changed how I develop
  code, both alone and with others
• The speed and easy branching/merging are
  game-changers
• It’s really not that hard to start using...
• ... and once you start, you’ll never want to
  go back to CVS or SVN
Want to learn more?
• Mailing lists, wikis, and blogs
 • http://git-scm.com/
 • http://progit.org/
 • http://gitimmersion.com/
• I’m probably going to offer Git training
  soon — let me know if you’re interested!
Thanks!
(Any questions?)
     reuven@lerner.co.il
   http://www.lerner.co.il/
        054-496-8405
“reuvenlerner” on Skype/AIM

More Related Content

PPT
Git Introduction
PDF
Git training
PDF
Git - The Incomplete Introduction
PDF
Git, from the beginning
PDF
Presentacion git
PDF
Enjoy fighting regressions_with_git_bisect
PDF
Git and Testing
PDF
Git tutorial
Git Introduction
Git training
Git - The Incomplete Introduction
Git, from the beginning
Presentacion git
Enjoy fighting regressions_with_git_bisect
Git and Testing
Git tutorial

What's hot (18)

PDF
New Views on your History with git replace
PDF
Inside GitHub with Chris Wanstrath
PDF
Introduction to Git, DrupalCamp LA 2015
PPTX
PDF
Deep dark-side of git: How git works internally
PDF
slides.pdf
PDF
git and github
PDF
Introduction to Git (part 1)
PDF
Github - Git Training Slides: Foundations
PDF
Introduction to Git
PDF
Starting with Git & GitHub
PPTX
Git 101 for Beginners
PDF
Git: An introduction of plumbing and porcelain commands
KEY
Git and GitHub
PPTX
Git One Day Training Notes
PDF
Now i git it!!!
PDF
Git training v10
PDF
Code review and automated testing for Puppet code
New Views on your History with git replace
Inside GitHub with Chris Wanstrath
Introduction to Git, DrupalCamp LA 2015
Deep dark-side of git: How git works internally
slides.pdf
git and github
Introduction to Git (part 1)
Github - Git Training Slides: Foundations
Introduction to Git
Starting with Git & GitHub
Git 101 for Beginners
Git: An introduction of plumbing and porcelain commands
Git and GitHub
Git One Day Training Notes
Now i git it!!!
Git training v10
Code review and automated testing for Puppet code
Ad

Viewers also liked (12)

PDF
Big Data — Your new best friend
KEY
PostgreSQL talk, Database 2011 conference
PDF
What can Ruby learn from Python (and vice versa)?
PDF
ActiveRecord 2.3
PDF
Functional Python Webinar from October 22nd, 2014
PDF
Web APIs: The future of software
KEY
Rails console
PDF
Dynamic languages, for software craftmanship group
PDF
Python's magic methods
KEY
PostgreSQL
PDF
Technical training business talk.key
PDF
Intro to cloud computing — MegaCOMM 2013, Jerusalem
Big Data — Your new best friend
PostgreSQL talk, Database 2011 conference
What can Ruby learn from Python (and vice versa)?
ActiveRecord 2.3
Functional Python Webinar from October 22nd, 2014
Web APIs: The future of software
Rails console
Dynamic languages, for software craftmanship group
Python's magic methods
PostgreSQL
Technical training business talk.key
Intro to cloud computing — MegaCOMM 2013, Jerusalem
Ad

Similar to Git talk from Open 2011 conference in Israel (20)

PPT
Introduction to Git for developers
PDF
Introduction to Git
KEY
Working with Git
PDF
What the git? - SAP Inside Track Munich 2016
PDF
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
PDF
Git SVN Migrate Reasons
PPTX
Git Github GDSC.pptx
PDF
Introduction to git, an efficient distributed version control system
PPTX
Git training (basic)
ODP
Introduction to Git
PPT
CSE 390 Lecture 9 - Version Control with GIT
PPT
Fundamentals and basics of Git and commands
PDF
Git Pocket Guide A Working Introduction 1st Edition Richard E. Silverman
PPT
Introduction to Git
PDF
Using GIT
PPTX
Getting Started with Git: A Primer for SVN and TFS Users
PPTX
Git and github
PPT
Introduction to git
KEY
Gitting the Most From Git
Introduction to Git for developers
Introduction to Git
Working with Git
What the git? - SAP Inside Track Munich 2016
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Git SVN Migrate Reasons
Git Github GDSC.pptx
Introduction to git, an efficient distributed version control system
Git training (basic)
Introduction to Git
CSE 390 Lecture 9 - Version Control with GIT
Fundamentals and basics of Git and commands
Git Pocket Guide A Working Introduction 1st Edition Richard E. Silverman
Introduction to Git
Using GIT
Getting Started with Git: A Primer for SVN and TFS Users
Git and github
Introduction to git
Gitting the Most From Git

More from Reuven Lerner (9)

PDF
PostgreSQL, your NoSQL database
PDF
Rails israel 2013
KEY
Rails traps
KEY
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
KEY
Rails development environment talk
KEY
Modern Web Technologies — Jerusalem Web Professionals, January 2011
KEY
Ruby objects
KEY
Rails tools
KEY
Why ruby and rails
PostgreSQL, your NoSQL database
Rails israel 2013
Rails traps
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Rails development environment talk
Modern Web Technologies — Jerusalem Web Professionals, January 2011
Ruby objects
Rails tools
Why ruby and rails

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing

Git talk from Open 2011 conference in Israel

  • 1. Git Reuven M. Lerner • reuven@lerner.co.il Open Israel Conference June 30th, 2011
  • 2. Who am I? • Web developer, software architect, consultant, lecturer/trainer • Linux Journal columnist since 1996 • Mostly Ruby on Rails + PostgreSQL, but also Python, PHP, jQuery, and lots more... • Git user (and enthusiast) since 2008
  • 4. Time machine • Return to any point in a project’s history • Find out how files, folders have changed • Learn which user made which changes
  • 5. Backup • Never fear that you’ve deleted a file — just rewind the history • Everything is recorded, can be undone
  • 6. Maintenance tool • “Tag” releases • Who is to blame for a particular bug? • When did we introduce a particular problem? • Deploy specific versions on specific servers
  • 7. Scratchpad • Try out new ideas • Experiment with alternative techniques • Upgrade a library • Refactor without affecting the “live” code base
  • 8. Collaboration tool • Work without fear of “stomping” on someone else’s code • Identify conflicts between what developers wrote • Mix and match teams for projects
  • 9. Version control is great • If you’re a programmer and not using version control, you’re really missing out • It’s also good for non-programs, such as configuration files • If you’re a CTO/team leader/VP R&D and your people aren’t using version control, you’re inviting disaster
  • 10. What do people use? • RCS (ancient history) • CVS (should be ancient history) • Subversion (“a better CVS”) • SourceSafe • Perforce • lots of other systems
  • 11. Problems with these • Work requires a server connection • (You can work, but not commit.) • Branching and merging is painful and slow • So no one does it! • Enforces a particular workflow • More code, more developers — slower VC
  • 12. Distributed version control • Distributed: Everyone is their own server! • Everyone has a complete commit history • No single point of failure • Commit whenever you want (i.e., often) • Merge when two repositories connect
  • 13. Git • Linus needed a VCS... so he wrote one! • Fast • Accurate • Distributed • Massively scalable • Super flexible
  • 14. Open-source Git users • Linux kernel • PostgreSQL • Ruby language • Ruby on Rails • Perl language • among many, many others
  • 15. Give me details! • What does Git do that others don’t? • Why do I claim that Git has changed my life?
  • 16. Branching & merging • Branching and merging is both easy and fast in Git • I often branch and merge several times in a given day • When I used SVN, I would do everything in my power to avoid branching, because merges were long and difficult
  • 17. Branching & merging • Create a branch: git checkout -b new-branch • Merge commits from other-branch git merge other-branch • Yes, it’s really that easy. • You don’t even have to change directories!
  • 18. Easy branching changes everything! • Every new feature goes in a branch • Merging becomes easy, fast, and natural • Side projects are stored, not kept out of version control for fear of “contamination” • Commit, commit, commit all of the time, in an appropriate branch — never lose work!
  • 19. Local repository is great • Work without a network connection • Commits, merges, and switching branches are nearly instantaneous • Reports and logs are super-fast • “Show me all files modified on Tuesday of last week” produces immediate resultss
  • 20. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 21. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 22. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 23. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 24. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 25. Create a repository! /tmp $ cd myapp /tmp/myapp $ git init Initialized empty Git repository in /private/tmp/myapp/.git/ master ✗ /tmp/myapp $ git add . master ✗ /tmp/myapp $ git commit -a -m 'Initial commit' [master (root-commit) 030c6b6] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo Initial commit master ✔ /tmp/myapp $
  • 26. The result master ✔ /tmp/myapp $ git log commit 030c6b691993e0f43d78119d9ff1c9e759120d11 Author: Reuven Lerner <reuven@lerner.co.il> Date: Thu Jun 30 12:29:29 2011 +0300 I
  • 27. Committing in stages • You can commit all modified files (“git commit -a”) • You can add files to be committed (“git add foo.rb”) over time • Using the staging area gives you tremendous flexibility before committing
  • 28. Remote branches • A local branch can “track” a remote branch • Different branches can be on different servers — and then you can merge across them • One possible workflow: Read from one remote branch, and write to another
  • 29. Integration • Git is all small Unix commands • Easily integrated into text editors, IDEs, cron jobs, monitoring, and system tasks • Example: Continuous integration servers • Example: Code-analysis tools • Also: Front ends to SVN and others!
  • 30. git blame • Shows the commit, user, and timestamp of when each line of a file was changed • Useful when you want to know who broke the build • Also useful for deflecting blame from clients, who think you broke something!
  • 31. a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 29) a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 30) #ifdef WIN32 65e806cb (Bruce Momjian 2010-02-26 02:01:40 +0000 31) #define FD_SETSIZE 1024 a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 32) #endif /* ! WIN32 */ a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 33) d08741ea (Tom Lane 2001-02-10 02:31:31 +0000 34) #include "postgres_fe.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 35) a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 36) #include "libpq-fe.h" a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 37) #include "libpq/pqsignal.h" 3da0dfb4 (Tatsuo Ishii 2009-08-03 15:18:14 +0000 38) #include "portability/instr_time.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 39) d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 40) #include <ctype.h> d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 41) a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 42) #ifndef WIN32 a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 43) #include <sys/time.h> a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 44) #include <unistd.h> ffda6747 (Tom Lane 2007-09-27 20:39:43 +0000 45) #endif /* ! WIN32 */
  • 32. Commit a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 29) a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 30) #ifdef WIN32 65e806cb (Bruce Momjian 2010-02-26 02:01:40 +0000 31) #define FD_SETSIZE 1024 a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 32) #endif /* ! WIN32 */ a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 33) d08741ea (Tom Lane 2001-02-10 02:31:31 +0000 34) #include "postgres_fe.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 35) a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 36) #include "libpq-fe.h" a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 37) #include "libpq/pqsignal.h" 3da0dfb4 (Tatsuo Ishii 2009-08-03 15:18:14 +0000 38) #include "portability/instr_time.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 39) d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 40) #include <ctype.h> d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 41) a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 42) #ifndef WIN32 a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 43) #include <sys/time.h> a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 44) #include <unistd.h> ffda6747 (Tom Lane 2007-09-27 20:39:43 +0000 45) #endif /* ! WIN32 */
  • 33. Commit User a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 29) a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 30) #ifdef WIN32 65e806cb (Bruce Momjian 2010-02-26 02:01:40 +0000 31) #define FD_SETSIZE 1024 a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 32) #endif /* ! WIN32 */ a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 33) d08741ea (Tom Lane 2001-02-10 02:31:31 +0000 34) #include "postgres_fe.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 35) a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 36) #include "libpq-fe.h" a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 37) #include "libpq/pqsignal.h" 3da0dfb4 (Tatsuo Ishii 2009-08-03 15:18:14 +0000 38) #include "portability/instr_time.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 39) d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 40) #include <ctype.h> d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 41) a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 42) #ifndef WIN32 a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 43) #include <sys/time.h> a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 44) #include <unistd.h> ffda6747 (Tom Lane 2007-09-27 20:39:43 +0000 45) #endif /* ! WIN32 */
  • 34. Commit User Timestamp a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 29) a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 30) #ifdef WIN32 65e806cb (Bruce Momjian 2010-02-26 02:01:40 +0000 31) #define FD_SETSIZE 1024 a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 32) #endif /* ! WIN32 */ a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 33) d08741ea (Tom Lane 2001-02-10 02:31:31 +0000 34) #include "postgres_fe.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 35) a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 36) #include "libpq-fe.h" a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 37) #include "libpq/pqsignal.h" 3da0dfb4 (Tatsuo Ishii 2009-08-03 15:18:14 +0000 38) #include "portability/instr_time.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 39) d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 40) #include <ctype.h> d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 41) a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 42) #ifndef WIN32 a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 43) #include <sys/time.h> a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 44) #include <unistd.h> ffda6747 (Tom Lane 2007-09-27 20:39:43 +0000 45) #endif /* ! WIN32 */
  • 35. Commit User Timestamp Line # and code a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 29) a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 30) #ifdef WIN32 65e806cb (Bruce Momjian 2010-02-26 02:01:40 +0000 31) #define FD_SETSIZE 1024 a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 32) #endif /* ! WIN32 */ a23c6415 (Magnus Hagander 2009-07-30 09:28:00 +0000 33) d08741ea (Tom Lane 2001-02-10 02:31:31 +0000 34) #include "postgres_fe.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 35) a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 36) #include "libpq-fe.h" a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 37) #include "libpq/pqsignal.h" 3da0dfb4 (Tatsuo Ishii 2009-08-03 15:18:14 +0000 38) #include "portability/instr_time.h" a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 39) d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 40) #include <ctype.h> d156e1f8 (Tom Lane 2005-10-07 15:34:17 +0000 41) a8a198b1 (Itagaki Takahiro 2010-01-06 01:30:03 +0000 42) #ifndef WIN32 a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 43) #include <sys/time.h> a765db40 (Tatsuo Ishii 2000-01-15 12:38:09 +0000 44) #include <unistd.h> ffda6747 (Tom Lane 2007-09-27 20:39:43 +0000 45) #endif /* ! WIN32 */
  • 36. git bisect • You introduced a bug, but don’t know where? Git can find it! • Give two endpoints • Git does a binary search between them • For each commit, tell Git whether it is “good” or “bad” • This finds the bug very quickly
  • 37. Stash • Temporary storage space • Useful if you have done enough work to keep, but not enough for a commit • Emergency fixes in the middle of working on something else • If you need, put the stash into a new branch • Oh, you can have multiple stashes
  • 38. Hooks • Execute arbitrary code when things happen • Example: Update submodules automatically • Example: Send e-mail after a commit • Example: Heroku uses hooks to deploy a new version of your Web app when you push to them!
  • 39. Workflows • Git supports many, many workflows • Traditional centralized server • BDFL and users • BDFL and Lieutenants • Do what works for you!
  • 43. Cherry picking • You can merge specific commits, or parts of commits • Amazingly powerful
  • 44. Rebase • An alternative to regular merging • First merge all external commits, then replay your changes on top • Helps to keep you aligned with remote branches • Avoids some merge-conflict issues
  • 45. Submodules • A Git repository can point to other repositories — submodules • Break a project into smaller projects • Git puts the pieces together for you!
  • 46. Amending commits • Commits are not sacred in Git • Rather, they are a tool to manage history • Change, amend, and edit commits • Yes, this can be dangerous! • Also avoids hundreds of “fixed typo” commits in a row...
  • 47. Commercial hosting • You can host Git repositories on your own • Want to go commercial? GitHub, Gitorious, and many others work great • GitHub is free for open-source projects, and thus very popular
  • 49. GUIs • Yes, there are now GUIs for Git • Windows, Mac, and Unix versions all exist • Integration with Emacs and other editors for hard-core hacker-nerds • Also: Shell-prompt integration for Unix
  • 50. In short • Git has completely changed how I develop code, both alone and with others • The speed and easy branching/merging are game-changers • It’s really not that hard to start using... • ... and once you start, you’ll never want to go back to CVS or SVN
  • 51. Want to learn more? • Mailing lists, wikis, and blogs • http://git-scm.com/ • http://progit.org/ • http://gitimmersion.com/ • I’m probably going to offer Git training soon — let me know if you’re interested!
  • 52. Thanks! (Any questions?) reuven@lerner.co.il http://www.lerner.co.il/ 054-496-8405 “reuvenlerner” on Skype/AIM

Editor's Notes