SlideShare a Scribd company logo
1 of 61
Download to read offline
Gitting it under
(version) control
The Plan

•   What is Version Control?

•   Git Basics

•   Workflows

•   Other fun stuff
What is Version
        Control?
• It’s exactly what it sounds like.
• Sometimes called SCM (source control
  management).
• One codebase, one project.
• Lots of people changing it to get things
  done at the same time.
  •   How do we track those changes?

  •   How do we make sure I don’t step over your toes?
Different Approaches


•   Distributed vs. Centralized

•   Delta vs. Directed Acyclic Graph (DAG)
Muscle Memory FTW

# 0. Get a copy of the repository
git clone git@github.com:user/repo
# 1. Before you do any work...
git pull
# 2. Do work, edit files, but when you want to share it...
git commit -am "commit message"
# 3. Now send it to everyone else
git push
# GOTO Step 1.
Setting Up

•     Download Installer
    from http://git-scm.com/

•    A few commands you
    want to run right away:

git config --global user.name "Ankur Oberoi"
git config --global user.email "aoberoi@gmail.com"
git config --global color.ui true
git commands
•   Porcelain (high-level, “nice” for users)
     git−add          git−commit   git−log        git−reset
     git−branch       git−diff     git−mv         git−status
     git−checkout     git−fetch    git−merge      git−push
     git−clone        git-init     git−pull       git−tag
     git-archive      git-bisect   git-bundle     git-cherry-pick
     git-citool       git-clean    git-describe   git-format-patch
     ...              ...          ...            ...


•   Plumbing (low-level, deals with database & filesystem)

    git−apply         git−checkout−index   git−commit−tree      git−hash
    −object
    git−index−pack    git−init−db          git−merge−index      git−mktag
    git−mktree        git−pack−objects     git−prune−packed     git−read−tree
    git−repo−config   git−unpack−objects   git−update−index     git−write−tree
    git−cat−file      git−describe         git−diff−index       git−diff−files
    git-diff-index    git-diff-tree        git-for-each-ref     git-ls-files
    ...               ...                  ...                  ...
Getting a repository
•   One project, one .git (hidden) directory

•   Start it from initial code locally

                     •      git init


•   Clone it from somewhere else
                 •       git clone URL
Local Repository Operations




Working Directory   Staging Area   Repository
 “Working Tree”       “Index”      “Database”
Local Repository Operations


Readme.md
* AwesomeProj *

AwesomeProj
does x and y.




     Working Directory   Staging Area   Repository
      “Working Tree”       “Index”      “Database”
Local Repository Operations

  git add Readme.md


                    Readme.md
                    * AwesomeProj *

                    AwesomeProj
                    does x and y.




Working Directory        Staging Area   Repository
 “Working Tree”            “Index”      “Database”
Local Repository Operations

  git add Readme.md                  git commit -m “commit mess”


                                          Readme.md
                                          * AwesomeProj *

                                          AwesomeProj
                                          does x and y.




Working Directory     Staging Area           Repository
 “Working Tree”         “Index”              “Database”
Local Repository Operations
                     git status


     # On branch master
     nothing to commit (working directory clean)


Readme.md




 Working Directory    Staging Area        Repository
  “Working Tree”        “Index”           “Database”
Local Repository Operations
                             git status



# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   Readme.md
    (use "git checkout -- <file>..." to discard changes in working
        Readme.md
directory)
#   * AwesomeProj *
# modified:   Readme.md
#
no changes added to commit (use "git add" and/or "git commit -a")
    AwesomeProj
    does x, y and z.




         Working Directory    Staging Area       Repository
          “Working Tree”        “Index”          “Database”
Local Repository Operations
                         git status

            git add Readme.md
            # On branch master
            # Changes to be committed:
            #   (use "git reset HEAD <file>..."
            to unstage)
                   Readme.md
Readme.md   #
            # modified:   Readme.md
            #      * AwesomeProj *

                     AwesomeProj
                     does x, y and z.




 Working Directory        Staging Area     Repository
  “Working Tree”            “Index”        “Database”
Local Repository Operations

                                      git commit -m “new feat”



Readme.md                                    Readme.md
 [master ad9e3bf] new feat
1 files changed, 1 insertions(+), 1 deletions(-)
                                        * AwesomeProj           *

                                             AwesomeProj
                                             does x, y and z.




 Working Directory     Staging Area           Repository
  “Working Tree”         “Index”              “Database”
Local Repository Operations
                     git status

     # On branch master
     nothing to commit (working directory clean)


Readme.md




 Working Directory    Staging Area        Repository
  “Working Tree”        “Index”           “Database”
Local Repository Operations

         git add Readme.md                  git commit -m “commit mess”




       Working Directory     Staging Area           Repository
        “Working Tree”         “Index”              “Database”

git reset HEAD Readme.md
Local Repository Operations

         git add Readme.md                  git commit -m “commit mess”




                 X
        git checkout -- Readme.md


                  X
                  git checkout HEAD -- Readme.md
                  git reset --hard [HEAD]


       Working Directory     Staging Area           Repository
        “Working Tree”         “Index”              “Database”

git reset HEAD Readme.md
Branching & Merging
•       What is a commit?

    •    An object that points to trees/blobs in the .git directory

    •    addressed by a SHA1 hash (ad9e3b)

    •    contains info about author/commiter

    •    also contains pointers to “parent commits”
                              ad9e3b
Branching & Merging
•       What is a branch?
    •    A pointer to a commit

    •    logically, a separate concern in development

•       What is HEAD?
    •    A pointer to a branch
                             ad9e3b        master       HEAD
    •    Usually represents whats in the WT *now*
Branching & Merging
    git commit -m “new feature”



   ad9e3b      master       HEAD
Branching & Merging
    git commit -m “new feature”



   ad9e3b      master       HEAD
Branching & Merging
    git commit -m “new feature”



   ad9e3b



   c88da7       master      HEAD
Branching & Merging
                git branch issue8



       ad9e3b

                       master       HEAD

       c88da7
                       issue8




New branch for a separate logical concern
Branching & Merging
                      git checkout issue8



             ad9e3b

                             master

             c88da7
                             issue8         HEAD



Checkout actually changes the files in your Working
                       Tree
Branching & Merging
# Make changes in editor, add changes to staging...
git commit -m “redoing data structure”



          ad9e3b

                                     master

          c88da7

                        b9711f       issue8      HEAD




New commits have pointers to parent(s)
Branching & Merging
                      git checkout master



             ad9e3b

                                            master   HEAD

             c88da7
                             b9711f         issue8




Checkout actually changes the files in your Working
                       Tree
Branching & Merging
       # Making more commits...



   ad9e3b



   c88da7        b9711f       issue8




   f327e3                    master    HEAD
Branching & Merging
# Now we need to get that fix for issue8 into master
                  git merge issue8



         ad9e3b



         c88da7         b9711f       issue8




         f327e3                     master       HEAD
Branching & Merging
# Now we need to get that fix for issue8 into master
                  git merge issue8
 ad9e3b




 c88da7         b9711f       issue8




 f327e3          This is known as a “merge commit”

 a77106                     master       HEAD
Sharing Code with
             Remotes
•       How do we share code with others?

    •    git has stored URLs with aliases called “remotes”


    •     a few operations to move code from your local repository
        to and from a remote

    •    you get local copies of remote branches in your repo


    •    *branch related operations happen locally
Remotes
  •    By default, you always get one remote
      when you clone, it is called “origin”

  •     You can add more remotes using:
git remote add github git@github.com:aoberoi/testproj.git



      This URL can be ssh:// (most common),
        http://, https://, git://, or even file:///
Using Remotes
f327e3   master   HEAD
Using Remotes
                     origin/master HEAD

           f327e3

                     master      HEAD




Now what if someone else adds commits to origin?
Using Remotes
                             master      HEAD


f327e3

            3602ea           origin/master HEAD




  This new commit only exists on the server...
                 git fetch origin
Using Remotes
                         master      HEAD


f327e3

          3602ea        origin/master HEAD




         Now we have a local copy.
How do we continue working where the latest
         from the server left off?
Using Remotes
                            master      HEAD


f327e3

           3602ea           origin/master HEAD



 How do we continue working where the latest
          from the server left off?
             git merge origin/master
Using Remotes
              f327e3           master      HEAD




             3602ea            origin/master HEAD



                git merge origin/master


Fast-forward merge: my commit is in the history of
             what is to be merged in
Using Remotes
               f327e3          master     HEAD




              3602ea          origin/master HEAD



                  Pull is a shortcut:
           git pull = git fetch + git merge
No need to specify the argument to merge if you are
              on a “tracking branch”
Creating a Tracking
          Branch

•    If theres a new branch available on the
    server and you want to participate in
    developing on that “logical concern”
        git checkout -t origin/next-big-thing


      You are not checking out a remote
                   branch,
         you are creating a new one
Pushing Changes


•     Pushing can only be fast-forward commits,
    this prevents you from abandoning
    someone else’s changes
               git push origin master
Inspection and History

•   git log --pretty=oneline --graph

•   git diff [--cached]

•   git status

•   git remote show
Other Neat Tricks
•   git add -u

•   git stash

•   git push -u origin master

•   git push origin :badfeature

•   git log feature ^master

•   git add -i
Gotchas

•   Binary files? Images? Videos? Databases?

•   Detached HEAD

•   non fast-forward

•   git rm / git mv
Workflows
master is always
         deployable
•    Good general convention

•    Keep actual development on ‘topic’
    branches

•     When topic is complete and code is
    tested → merge (or pull request)
                      master



                     issue-8
master is always
         deployable
•    Good general convention

•    Keep actual development on ‘topic’
    branches

•     When topic is complete and code is
    tested → merge (or pull request)
                      master


                    issue-8
Local Development
•       Common pieces to share:

    •    unit tests


    •    graphics


    •    utility scripts


•    Keep your own preferences on your local
    machine and don’t commit them
.gitignore

•     A file with filename patterns that you
    don’t want to become part of your index
    (nor your commits)

•    See samples for all types of platforms:
    https://github.com/github/gitignore/
Mark versions with
              Tags
•       Tags are like “unmovable” branches

•     This makes it a good bookmark to keep
    track of code that was released

    •     “I need to patch a bug that my customer sees, but what
        code did I deploy?”
Github Pull-Requests
•    You don’t always have access to push if
    you are contributing to open source, send a
    pull-request

•       Pull-requests work from branch to branch

    •    use this for collaborative development


    •    code review


•       http://www.confreaks.com/videos/706-
Github Forks

•    Just a “clone” that you initialize on a
    remote server, instead of on your machine

•    Holds a little bit of history for the project
    so you can track relationships in a
    “network”
IDE and GUI Tools
      Xcode
IDE and GUI Tools
      Eclipse Egit
IDE and GUI Tools
•       Platform Specific Tools

    •     Tower for Mac


    •     TortoiseGit for Windows


•       Cross Platform

    •     gitk
Feeling more “at home”

•   Bash Completion

•   Merge Tool

•   Commit Message Editor

•   Aliases
Left as an exercise for
      the readers
•   cherry-picking
•   “rewriting” history
•   git-svn
•   git modules
•   environment variables and $GIT_DIR
•   Treeishes by ‘x’spec
•   Writing your own git hooks
Resources
•    Git Cheatsheet (visual)
    http://ndpsoftware.com/git-cheatsheet.html
•    Github Help
    http://help.github.com/git-cheat-sheets/
•    Pro Git
    http://progit.org/book/
•    Git Community Book
    http://book.git-scm.com/
•   Google Tech Talk with Linus Torvalds
Erasing any
Preconceived Notions
• If you came from svn, you have a separate
  understanding of version control
• commits happen locally (actually almost
  everything happens locally)
• version numbers are not monotonically
  increasing
• branches are not global (pollution of
  namespace?)
• merging is (relatively) cheap, can be done
Why distributed over
   centralized?
• Offline development
• Easy to do experimental work
• ... code review
• ... other workflowy specific purposes
  (flexibility)
• “commit access” politics are avoided
• backups

More Related Content

What's hot

Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby CoreHiroshi SHIBATA
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.Graham Dumpleton
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetColin Brown
 
Apache Hive Hook
Apache Hive HookApache Hive Hook
Apache Hive HookMinwoo Kim
 
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for HadoopMay 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for HadoopYahoo Developer Network
 
Chef & OpenStack: OSCON 2014
Chef & OpenStack: OSCON 2014Chef & OpenStack: OSCON 2014
Chef & OpenStack: OSCON 2014Matt Ray
 
Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용종민 김
 
Velocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack WorkshopVelocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack WorkshopChef Software, Inc.
 
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopAtlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopMatt Ray
 
July 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification ProcessJuly 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification ProcessYahoo Developer Network
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialJason Terpko
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a NutshellCoreOS
 

What's hot (20)

Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Hadoop 설치
Hadoop 설치Hadoop 설치
Hadoop 설치
 
Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.
 
Node.js in production
Node.js in productionNode.js in production
Node.js in production
 
Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3
 
Apache Cassandra and Go
Apache Cassandra and GoApache Cassandra and Go
Apache Cassandra and Go
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w Puppet
 
Apache Hive Hook
Apache Hive HookApache Hive Hook
Apache Hive Hook
 
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for HadoopMay 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
 
Chef & OpenStack: OSCON 2014
Chef & OpenStack: OSCON 2014Chef & OpenStack: OSCON 2014
Chef & OpenStack: OSCON 2014
 
Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용
 
Velocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack WorkshopVelocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack Workshop
 
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopAtlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
 
July 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification ProcessJuly 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification Process
 
Hadoop Oozie
Hadoop OozieHadoop Oozie
Hadoop Oozie
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a Nutshell
 

Viewers also liked

The Seven Deadly Coding Sins Slides
The Seven Deadly Coding Sins SlidesThe Seven Deadly Coding Sins Slides
The Seven Deadly Coding Sins Slidesmobiledevnj
 
квест-проект посвящённый 70летию Великой Победы
квест-проект посвящённый 70летию Великой Победы квест-проект посвящённый 70летию Великой Победы
квест-проект посвящённый 70летию Великой Победы Sample Splat
 
Delegation Slides
Delegation SlidesDelegation Slides
Delegation Slidesmobiledevnj
 
Ama ieee takeda
Ama ieee takedaAma ieee takeda
Ama ieee takedam-takeda
 
Tarea daa sesion3
Tarea daa sesion3Tarea daa sesion3
Tarea daa sesion3albycom7274
 
Storyboards Slides
Storyboards SlidesStoryboards Slides
Storyboards Slidesmobiledevnj
 

Viewers also liked (7)

The Seven Deadly Coding Sins Slides
The Seven Deadly Coding Sins SlidesThe Seven Deadly Coding Sins Slides
The Seven Deadly Coding Sins Slides
 
квест-проект посвящённый 70летию Великой Победы
квест-проект посвящённый 70летию Великой Победы квест-проект посвящённый 70летию Великой Победы
квест-проект посвящённый 70летию Великой Победы
 
Delegation Slides
Delegation SlidesDelegation Slides
Delegation Slides
 
Ama ieee takeda
Ama ieee takedaAma ieee takeda
Ama ieee takeda
 
Bab 4
Bab 4Bab 4
Bab 4
 
Tarea daa sesion3
Tarea daa sesion3Tarea daa sesion3
Tarea daa sesion3
 
Storyboards Slides
Storyboards SlidesStoryboards Slides
Storyboards Slides
 

Similar to Gitting It Under (Version) Control

Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlBecky Todd
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.comdropsolid
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHubLucas Videla
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 

Similar to Gitting It Under (Version) Control (20)

簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Git training
Git trainingGit training
Git training
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
T3dd10 git
T3dd10 gitT3dd10 git
T3dd10 git
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git presentation
Git presentationGit presentation
Git presentation
 
Git slides
Git slidesGit slides
Git slides
 
Gittalk
GittalkGittalk
Gittalk
 
Git101
Git101Git101
Git101
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Gitting It Under (Version) Control

  • 2. The Plan • What is Version Control? • Git Basics • Workflows • Other fun stuff
  • 3. What is Version Control? • It’s exactly what it sounds like. • Sometimes called SCM (source control management). • One codebase, one project. • Lots of people changing it to get things done at the same time. • How do we track those changes? • How do we make sure I don’t step over your toes?
  • 4. Different Approaches • Distributed vs. Centralized • Delta vs. Directed Acyclic Graph (DAG)
  • 5. Muscle Memory FTW # 0. Get a copy of the repository git clone git@github.com:user/repo # 1. Before you do any work... git pull # 2. Do work, edit files, but when you want to share it... git commit -am "commit message" # 3. Now send it to everyone else git push # GOTO Step 1.
  • 6. Setting Up • Download Installer from http://git-scm.com/ • A few commands you want to run right away: git config --global user.name "Ankur Oberoi" git config --global user.email "aoberoi@gmail.com" git config --global color.ui true
  • 7. git commands • Porcelain (high-level, “nice” for users) git−add git−commit git−log git−reset git−branch git−diff git−mv git−status git−checkout git−fetch git−merge git−push git−clone git-init git−pull git−tag git-archive git-bisect git-bundle git-cherry-pick git-citool git-clean git-describe git-format-patch ... ... ... ... • Plumbing (low-level, deals with database & filesystem) git−apply git−checkout−index git−commit−tree git−hash −object git−index−pack git−init−db git−merge−index git−mktag git−mktree git−pack−objects git−prune−packed git−read−tree git−repo−config git−unpack−objects git−update−index git−write−tree git−cat−file git−describe git−diff−index git−diff−files git-diff-index git-diff-tree git-for-each-ref git-ls-files ... ... ... ...
  • 8. Getting a repository • One project, one .git (hidden) directory • Start it from initial code locally • git init • Clone it from somewhere else • git clone URL
  • 9. Local Repository Operations Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 10. Local Repository Operations Readme.md * AwesomeProj * AwesomeProj does x and y. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 11. Local Repository Operations git add Readme.md Readme.md * AwesomeProj * AwesomeProj does x and y. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 12. Local Repository Operations git add Readme.md git commit -m “commit mess” Readme.md * AwesomeProj * AwesomeProj does x and y. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 13. Local Repository Operations git status # On branch master nothing to commit (working directory clean) Readme.md Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 14. Local Repository Operations git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # Readme.md (use "git checkout -- <file>..." to discard changes in working Readme.md directory) # * AwesomeProj * # modified: Readme.md # no changes added to commit (use "git add" and/or "git commit -a") AwesomeProj does x, y and z. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 15. Local Repository Operations git status git add Readme.md # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) Readme.md Readme.md # # modified: Readme.md # * AwesomeProj * AwesomeProj does x, y and z. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 16. Local Repository Operations git commit -m “new feat” Readme.md Readme.md [master ad9e3bf] new feat 1 files changed, 1 insertions(+), 1 deletions(-) * AwesomeProj * AwesomeProj does x, y and z. Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 17. Local Repository Operations git status # On branch master nothing to commit (working directory clean) Readme.md Working Directory Staging Area Repository “Working Tree” “Index” “Database”
  • 18. Local Repository Operations git add Readme.md git commit -m “commit mess” Working Directory Staging Area Repository “Working Tree” “Index” “Database” git reset HEAD Readme.md
  • 19. Local Repository Operations git add Readme.md git commit -m “commit mess” X git checkout -- Readme.md X git checkout HEAD -- Readme.md git reset --hard [HEAD] Working Directory Staging Area Repository “Working Tree” “Index” “Database” git reset HEAD Readme.md
  • 20. Branching & Merging • What is a commit? • An object that points to trees/blobs in the .git directory • addressed by a SHA1 hash (ad9e3b) • contains info about author/commiter • also contains pointers to “parent commits” ad9e3b
  • 21. Branching & Merging • What is a branch? • A pointer to a commit • logically, a separate concern in development • What is HEAD? • A pointer to a branch ad9e3b master HEAD • Usually represents whats in the WT *now*
  • 22. Branching & Merging git commit -m “new feature” ad9e3b master HEAD
  • 23. Branching & Merging git commit -m “new feature” ad9e3b master HEAD
  • 24. Branching & Merging git commit -m “new feature” ad9e3b c88da7 master HEAD
  • 25. Branching & Merging git branch issue8 ad9e3b master HEAD c88da7 issue8 New branch for a separate logical concern
  • 26. Branching & Merging git checkout issue8 ad9e3b master c88da7 issue8 HEAD Checkout actually changes the files in your Working Tree
  • 27. Branching & Merging # Make changes in editor, add changes to staging... git commit -m “redoing data structure” ad9e3b master c88da7 b9711f issue8 HEAD New commits have pointers to parent(s)
  • 28. Branching & Merging git checkout master ad9e3b master HEAD c88da7 b9711f issue8 Checkout actually changes the files in your Working Tree
  • 29. Branching & Merging # Making more commits... ad9e3b c88da7 b9711f issue8 f327e3 master HEAD
  • 30. Branching & Merging # Now we need to get that fix for issue8 into master git merge issue8 ad9e3b c88da7 b9711f issue8 f327e3 master HEAD
  • 31. Branching & Merging # Now we need to get that fix for issue8 into master git merge issue8 ad9e3b c88da7 b9711f issue8 f327e3 This is known as a “merge commit” a77106 master HEAD
  • 32. Sharing Code with Remotes • How do we share code with others? • git has stored URLs with aliases called “remotes” • a few operations to move code from your local repository to and from a remote • you get local copies of remote branches in your repo • *branch related operations happen locally
  • 33. Remotes • By default, you always get one remote when you clone, it is called “origin” • You can add more remotes using: git remote add github git@github.com:aoberoi/testproj.git This URL can be ssh:// (most common), http://, https://, git://, or even file:///
  • 34. Using Remotes f327e3 master HEAD
  • 35. Using Remotes origin/master HEAD f327e3 master HEAD Now what if someone else adds commits to origin?
  • 36. Using Remotes master HEAD f327e3 3602ea origin/master HEAD This new commit only exists on the server... git fetch origin
  • 37. Using Remotes master HEAD f327e3 3602ea origin/master HEAD Now we have a local copy. How do we continue working where the latest from the server left off?
  • 38. Using Remotes master HEAD f327e3 3602ea origin/master HEAD How do we continue working where the latest from the server left off? git merge origin/master
  • 39. Using Remotes f327e3 master HEAD 3602ea origin/master HEAD git merge origin/master Fast-forward merge: my commit is in the history of what is to be merged in
  • 40. Using Remotes f327e3 master HEAD 3602ea origin/master HEAD Pull is a shortcut: git pull = git fetch + git merge No need to specify the argument to merge if you are on a “tracking branch”
  • 41. Creating a Tracking Branch • If theres a new branch available on the server and you want to participate in developing on that “logical concern” git checkout -t origin/next-big-thing You are not checking out a remote branch, you are creating a new one
  • 42. Pushing Changes • Pushing can only be fast-forward commits, this prevents you from abandoning someone else’s changes git push origin master
  • 43. Inspection and History • git log --pretty=oneline --graph • git diff [--cached] • git status • git remote show
  • 44. Other Neat Tricks • git add -u • git stash • git push -u origin master • git push origin :badfeature • git log feature ^master • git add -i
  • 45. Gotchas • Binary files? Images? Videos? Databases? • Detached HEAD • non fast-forward • git rm / git mv
  • 47. master is always deployable • Good general convention • Keep actual development on ‘topic’ branches • When topic is complete and code is tested → merge (or pull request) master issue-8
  • 48. master is always deployable • Good general convention • Keep actual development on ‘topic’ branches • When topic is complete and code is tested → merge (or pull request) master issue-8
  • 49. Local Development • Common pieces to share: • unit tests • graphics • utility scripts • Keep your own preferences on your local machine and don’t commit them
  • 50. .gitignore • A file with filename patterns that you don’t want to become part of your index (nor your commits) • See samples for all types of platforms: https://github.com/github/gitignore/
  • 51. Mark versions with Tags • Tags are like “unmovable” branches • This makes it a good bookmark to keep track of code that was released • “I need to patch a bug that my customer sees, but what code did I deploy?”
  • 52. Github Pull-Requests • You don’t always have access to push if you are contributing to open source, send a pull-request • Pull-requests work from branch to branch • use this for collaborative development • code review • http://www.confreaks.com/videos/706-
  • 53. Github Forks • Just a “clone” that you initialize on a remote server, instead of on your machine • Holds a little bit of history for the project so you can track relationships in a “network”
  • 54. IDE and GUI Tools Xcode
  • 55. IDE and GUI Tools Eclipse Egit
  • 56. IDE and GUI Tools • Platform Specific Tools • Tower for Mac • TortoiseGit for Windows • Cross Platform • gitk
  • 57. Feeling more “at home” • Bash Completion • Merge Tool • Commit Message Editor • Aliases
  • 58. Left as an exercise for the readers • cherry-picking • “rewriting” history • git-svn • git modules • environment variables and $GIT_DIR • Treeishes by ‘x’spec • Writing your own git hooks
  • 59. Resources • Git Cheatsheet (visual) http://ndpsoftware.com/git-cheatsheet.html • Github Help http://help.github.com/git-cheat-sheets/ • Pro Git http://progit.org/book/ • Git Community Book http://book.git-scm.com/ • Google Tech Talk with Linus Torvalds
  • 60. Erasing any Preconceived Notions • If you came from svn, you have a separate understanding of version control • commits happen locally (actually almost everything happens locally) • version numbers are not monotonically increasing • branches are not global (pollution of namespace?) • merging is (relatively) cheap, can be done
  • 61. Why distributed over centralized? • Offline development • Easy to do experimental work • ... code review • ... other workflowy specific purposes (flexibility) • “commit access” politics are avoided • backups