SlideShare a Scribd company logo
An Introduction to Git


                                                 James Herdman, Dec. 2010
                                                 Twitter: james_herdman
                                                 Github: http://github.com/jherdman

Friday, December 17, 2010                                                             1
Who Am I?

                            •James Herdman
                            • Ruby and JavaScript programmer
                            • Work for Celect.org
                            • Git user for 3 years




Friday, December 17, 2010                                      2
I   Git

Friday, December 17, 2010             3
Goals


                            • Basic Git workflow
                            • Build a strong foundation
                            • Point you towards your next step


Friday, December 17, 2010                                        4
Basic.



Friday, December 17, 2010            5
Our Journey


                            • Git at a Glance
                            • What is Version Control?
                            • Using Git


Friday, December 17, 2010                                   6
Git at a Glance

                            • Version Control System
                            • Supports non-linear development
                            • Cryptographic authentication of history
                            • UNIX principles
                            • Bloody fast

Friday, December 17, 2010                                               7
Version Control

                            •Managing changes to documents
                            • Prevent loss of work
                            • Sharing documents safely
                            • Maintain versions of documents




Friday, December 17, 2010                                      8
Version Control is a Misnomer



Friday, December 17, 2010                                   9
(in Git)



Friday, December 17, 2010              10
It’s All About Changes

                            •Change: a difference in content
                            • History: a collection of changes
                            • Loss of work: loss of changes
                            • Version: collection of documents, at a point in time

Friday, December 17, 2010                                                            11
NAME
                                   git - the stupid content tracker




Friday, December 17, 2010                                             12
NAME
                                   git - the stupid content tracker




Friday, December 17, 2010                                             13
Let’s Get Started!



Friday, December 17, 2010                        14
~ ➜ git init blog
                            Initialized empty Git repository in ~blog/.git/




Friday, December 17, 2010                                                     15
~blog ➜ git status
                            # On branch master
                            #
                            # Initial commit
                            #
                            # Untracked files:
                            #   (use "git add <file>..." to include in what will be committed)
                            #
                            #" lorem.txt
                            nothing added to commit but untracked files present (use "git add" to track)




Friday, December 17, 2010                                                                                  16
What’s a Commit?


                            • A change, recorded and tracked by Git
                            • A point in a project’s history




Friday, December 17, 2010                                             17
Making a Commit

                            1.Make a change
                            2.Track it
                            3.Commit it




Friday, December 17, 2010                                   18
~blog ➜ git add lorem.txt




Friday, December 17, 2010                               19
~blog ➜ git status
                            # On branch master
                            #
                            # Initial commit
                            #
                            # Changes to be committed:
                            #   (use "git rm --cached <file>..." to unstage)
                            #
                            #" new file:   lorem.txt
                            #




Friday, December 17, 2010                                                      20
~blog ➜ git commit -m "Initial blog entry"
                            [master (root-commit) 5a93468] Initial blog entry
                             1 files changed, 5 insertions(+), 0 deletions(-)
                             create mode 100644 lorem.txt




Friday, December 17, 2010                                                       21
~blog ➜ git status
                            # On branch master
                            nothing to commit (working directory clean)




Friday, December 17, 2010                                                 22
Commit Life Cycle




                                                “Pro Git”, Scott Chacon. Apress. 2010

Friday, December 17, 2010                                                               23
~blog ➜ git status
           # On branch master
           # Changed but not updated:
           #   (use "git add <file>..." to update what will be committed)
           #   (use "git checkout -- <file>..." to discard changes in working directory)
           #
           #" modified:   lorem.txt
           #
           no changes added to commit (use "git add" and/or "git commit -a")




Friday, December 17, 2010                                                                  24
~blog ➜ git status
                            # On branch master
                            # Changes to be committed:
                            #   (use "git reset HEAD <file>..." to unstage)
                            #
                            #" modified:   lorem.txt
                            #




Friday, December 17, 2010                                                     25
~blog ➜ git commit -m "Start of a new line"
                            [master 3584954] Start of a new line
                             1 files changed, 4 insertions(+), 1 deletions(-)




Friday, December 17, 2010                                                       26
What Happened?


                            • Change given unique ID
                            • SHA hex digest of the change itself
                            • Stored in Git’s log (the history)


Friday, December 17, 2010                                           27
~blog ➜ git show -p
               commit 35849545dae48e9b3d073f77a868f8978c95e5a5
               Author: James F. Herdman <james.code@me.com>
               Date:   Mon Dec 13 20:00:35 2010 -0500

                            Start of a new line

               diff --git a/lorem.txt b/lorem.txt
               index 1184641..0e2bb4f 100644
               --- a/lorem.txt
               +++ b/lorem.txt
               @@ -2,4 +2,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce e

                  Maecenas id erat sem, id eleifend nulla. Phasellus eget risus egestas erat cons

               -Quisque vel mi          quis nisl gravida consequat ut vel erat. Cras blandit mollis sap
                No newline at          end of file
               +Quisque vel mi          quis nisl gravida consequat ut vel erat. Cras blandit mollis sap
               +
               +There once was          a tool named Git,
               +that Linus was          sure would be a hit.




Friday, December 17, 2010                                                                                  28
Branching and Merging



Friday, December 17, 2010                           29
Branching


                            • Divergence from main path
                            • Isolate new ideas
                            • Allow for safe collaboration


Friday, December 17, 2010                                    30
Merging


                            • Combining merge in one branch with another



Friday, December 17, 2010                                                  31
~snipmate.vim ➜ git branch better-javascript-snippets

                            ~snipmate.vim ➜ git branch
                              better-javascript-snippets
                            * master

                            ~snipmate.vim ➜ git checkout better-javascript-snippets
                            Switched to branch 'better-javascript-snippets'

                            ~snipmate.vim ➜ git branch
                            * better-javascript-snippets
                              master




Friday, December 17, 2010                                                             32
Make Changes



Friday, December 17, 2010                  33
Friday, December 17, 2010   34
~snipmate.vim ➜ git branch
                            * better-javascript-snippets
                              master

                            ~snipmate.vim ➜ git checkout master
                            Switched to branch 'master'
                            Your branch is ahead of 'origin/master' by 1 commit.

                            ~snipmate.vim ➜ git merge better-javascript-snippets
                            Merge made by recursive.
                             snippets/javascript.snippets |   17 +++++++++++------
                             1 files changed, 11 insertions(+), 6 deletions(-)

                            ~snipmate.vim ➜ git status
                            # On branch master
                            # Your branch is ahead of 'origin/master' by 5 commits.
                            #
                            nothing to commit (working directory clean)




Friday, December 17, 2010                                                             35
One More Thing



Friday, December 17, 2010                    36
The Stash



Friday, December 17, 2010               37
“Hey. Can you fix just this one thing?”

Friday, December 17, 2010                                            38
“Sure. No problem!”



Friday, December 17, 2010                         39
~snipmate.vim ➜ git status
       # On branch master
       # Your branch is ahead of 'origin/master' by 5 commits.
       #
       # Changed but not updated:
       #   (use "git add <file>..." to update what will be committed)
       #   (use "git checkout -- <file>..." to discard changes in working directory)
       #
       #" modified:   javascript.snippets
       #
       no changes added to commit (use "git add" and/or "git commit -a")




Friday, December 17, 2010                                                              40
~snipmate.vim/ ➜ git stash
   Saved working directory and index state WIP on master: 604f234 Merge branch 'better-javascript-
   snippets'
   HEAD is now at 604f234 Merge branch 'better-javascript-snippets'




Friday, December 17, 2010                                                                            41
~snipmate.vim ➜ git status
                            # On branch master
                            # Your branch is ahead of 'origin/master' by 5 commits.
                            #
                            nothing to commit (working directory clean)




Friday, December 17, 2010                                                             42
~snipmate.vim ➜ git stash pop
        # On branch master
        # Your branch is ahead of 'origin/master' by 5 commits.
        #
        # Changed but not updated:
        #   (use "git add <file>..." to update what will be committed)
        #   (use "git checkout -- <file>..." to discard changes in working directory)
        #
        #" modified:   snippets/javascript.snippets
        #
        no changes added to commit (use "git add" and/or "git commit -a")
        Dropped refs/stash@{0} (b7033f1c44071a8d69a4c8d4716b5781ac117e97)




Friday, December 17, 2010                                                               43
What’s Next?
                            •Pushing
                            • Pulling
                            • Cherry picking
                            • Tagging
                            • Workflows
                            • More!


Friday, December 17, 2010                                     44
What’s Next?

                            • Git for Designers. http://hoth.entp.com/output/
                              git_for_designers.html

                            • The Git Parable. http://tom.preston-werner.com/2009/05/19/the-git-
                              parable.html

                            • Pro Git. http://progit.org
                            • Git homepage. http://git-scm.com

Friday, December 17, 2010                                                                          45
Questions?



Friday, December 17, 2010                46
Fin.



Friday, December 17, 2010          47

More Related Content

PDF
Debugging and Profiling Symfony Apps
PDF
PostgreSQL Development Today: 9.0
PDF
Building Distributed JavaScript Widgets with jQuery
PDF
Is these a bug
PDF
Controle de versão com git
PDF
App in a Browser
PDF
Git in Eclipse
PDF
Git training with Devaamo
Debugging and Profiling Symfony Apps
PostgreSQL Development Today: 9.0
Building Distributed JavaScript Widgets with jQuery
Is these a bug
Controle de versão com git
App in a Browser
Git in Eclipse
Git training with Devaamo

Similar to Introduction to Git (20)

PDF
The State of the Social Desktop 2009
ODP
Git for standalone use
PDF
Git - The Incomplete Introduction
PDF
Git in gear: How to track changes, travel back in time, and code nicely with ...
PDF
Thinking in Git
PDF
Intro to Git
PDF
Jeff mc cune sf 2010
PDF
GGUG:Practical DSL Design
PDF
Beginning git
PDF
Git! Why? How?
PDF
The Social Desktop - Keynote Akademy 2008
PDF
Learning git
PDF
Document-Oriented Databases: Couchdb Primer
PDF
How Git and Gerrit make you more productive
PPTX
Git Overview
KEY
Working with Git
PDF
Robb broome rubyconf x presentation for publication
ODP
Git - (a) Gentle InTroduction
ODP
The Fundamentals of Git
PPTX
Git and github introduction
The State of the Social Desktop 2009
Git for standalone use
Git - The Incomplete Introduction
Git in gear: How to track changes, travel back in time, and code nicely with ...
Thinking in Git
Intro to Git
Jeff mc cune sf 2010
GGUG:Practical DSL Design
Beginning git
Git! Why? How?
The Social Desktop - Keynote Akademy 2008
Learning git
Document-Oriented Databases: Couchdb Primer
How Git and Gerrit make you more productive
Git Overview
Working with Git
Robb broome rubyconf x presentation for publication
Git - (a) Gentle InTroduction
The Fundamentals of Git
Git and github introduction
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Network Security Unit 5.pdf for BCA BBA.
Ad

Introduction to Git

  • 1. An Introduction to Git James Herdman, Dec. 2010 Twitter: james_herdman Github: http://github.com/jherdman Friday, December 17, 2010 1
  • 2. Who Am I? •James Herdman • Ruby and JavaScript programmer • Work for Celect.org • Git user for 3 years Friday, December 17, 2010 2
  • 3. I Git Friday, December 17, 2010 3
  • 4. Goals • Basic Git workflow • Build a strong foundation • Point you towards your next step Friday, December 17, 2010 4
  • 6. Our Journey • Git at a Glance • What is Version Control? • Using Git Friday, December 17, 2010 6
  • 7. Git at a Glance • Version Control System • Supports non-linear development • Cryptographic authentication of history • UNIX principles • Bloody fast Friday, December 17, 2010 7
  • 8. Version Control •Managing changes to documents • Prevent loss of work • Sharing documents safely • Maintain versions of documents Friday, December 17, 2010 8
  • 9. Version Control is a Misnomer Friday, December 17, 2010 9
  • 11. It’s All About Changes •Change: a difference in content • History: a collection of changes • Loss of work: loss of changes • Version: collection of documents, at a point in time Friday, December 17, 2010 11
  • 12. NAME git - the stupid content tracker Friday, December 17, 2010 12
  • 13. NAME git - the stupid content tracker Friday, December 17, 2010 13
  • 14. Let’s Get Started! Friday, December 17, 2010 14
  • 15. ~ ➜ git init blog Initialized empty Git repository in ~blog/.git/ Friday, December 17, 2010 15
  • 16. ~blog ➜ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # #" lorem.txt nothing added to commit but untracked files present (use "git add" to track) Friday, December 17, 2010 16
  • 17. What’s a Commit? • A change, recorded and tracked by Git • A point in a project’s history Friday, December 17, 2010 17
  • 18. Making a Commit 1.Make a change 2.Track it 3.Commit it Friday, December 17, 2010 18
  • 19. ~blog ➜ git add lorem.txt Friday, December 17, 2010 19
  • 20. ~blog ➜ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # #" new file: lorem.txt # Friday, December 17, 2010 20
  • 21. ~blog ➜ git commit -m "Initial blog entry" [master (root-commit) 5a93468] Initial blog entry 1 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 lorem.txt Friday, December 17, 2010 21
  • 22. ~blog ➜ git status # On branch master nothing to commit (working directory clean) Friday, December 17, 2010 22
  • 23. Commit Life Cycle “Pro Git”, Scott Chacon. Apress. 2010 Friday, December 17, 2010 23
  • 24. ~blog ➜ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # #" modified: lorem.txt # no changes added to commit (use "git add" and/or "git commit -a") Friday, December 17, 2010 24
  • 25. ~blog ➜ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # #" modified: lorem.txt # Friday, December 17, 2010 25
  • 26. ~blog ➜ git commit -m "Start of a new line" [master 3584954] Start of a new line 1 files changed, 4 insertions(+), 1 deletions(-) Friday, December 17, 2010 26
  • 27. What Happened? • Change given unique ID • SHA hex digest of the change itself • Stored in Git’s log (the history) Friday, December 17, 2010 27
  • 28. ~blog ➜ git show -p commit 35849545dae48e9b3d073f77a868f8978c95e5a5 Author: James F. Herdman <james.code@me.com> Date: Mon Dec 13 20:00:35 2010 -0500 Start of a new line diff --git a/lorem.txt b/lorem.txt index 1184641..0e2bb4f 100644 --- a/lorem.txt +++ b/lorem.txt @@ -2,4 +2,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce e Maecenas id erat sem, id eleifend nulla. Phasellus eget risus egestas erat cons -Quisque vel mi quis nisl gravida consequat ut vel erat. Cras blandit mollis sap No newline at end of file +Quisque vel mi quis nisl gravida consequat ut vel erat. Cras blandit mollis sap + +There once was a tool named Git, +that Linus was sure would be a hit. Friday, December 17, 2010 28
  • 29. Branching and Merging Friday, December 17, 2010 29
  • 30. Branching • Divergence from main path • Isolate new ideas • Allow for safe collaboration Friday, December 17, 2010 30
  • 31. Merging • Combining merge in one branch with another Friday, December 17, 2010 31
  • 32. ~snipmate.vim ➜ git branch better-javascript-snippets ~snipmate.vim ➜ git branch better-javascript-snippets * master ~snipmate.vim ➜ git checkout better-javascript-snippets Switched to branch 'better-javascript-snippets' ~snipmate.vim ➜ git branch * better-javascript-snippets master Friday, December 17, 2010 32
  • 35. ~snipmate.vim ➜ git branch * better-javascript-snippets master ~snipmate.vim ➜ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 1 commit. ~snipmate.vim ➜ git merge better-javascript-snippets Merge made by recursive. snippets/javascript.snippets | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) ~snipmate.vim ➜ git status # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # nothing to commit (working directory clean) Friday, December 17, 2010 35
  • 36. One More Thing Friday, December 17, 2010 36
  • 38. “Hey. Can you fix just this one thing?” Friday, December 17, 2010 38
  • 39. “Sure. No problem!” Friday, December 17, 2010 39
  • 40. ~snipmate.vim ➜ git status # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # #" modified: javascript.snippets # no changes added to commit (use "git add" and/or "git commit -a") Friday, December 17, 2010 40
  • 41. ~snipmate.vim/ ➜ git stash Saved working directory and index state WIP on master: 604f234 Merge branch 'better-javascript- snippets' HEAD is now at 604f234 Merge branch 'better-javascript-snippets' Friday, December 17, 2010 41
  • 42. ~snipmate.vim ➜ git status # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # nothing to commit (working directory clean) Friday, December 17, 2010 42
  • 43. ~snipmate.vim ➜ git stash pop # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # #" modified: snippets/javascript.snippets # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (b7033f1c44071a8d69a4c8d4716b5781ac117e97) Friday, December 17, 2010 43
  • 44. What’s Next? •Pushing • Pulling • Cherry picking • Tagging • Workflows • More! Friday, December 17, 2010 44
  • 45. What’s Next? • Git for Designers. http://hoth.entp.com/output/ git_for_designers.html • The Git Parable. http://tom.preston-werner.com/2009/05/19/the-git- parable.html • Pro Git. http://progit.org • Git homepage. http://git-scm.com Friday, December 17, 2010 45