SlideShare una empresa de Scribd logo
1 de 84
Hello!
Gitting the Most From Git
Who am I?
•   For the people in the room:

      •   You know me

•   Everyone else:

      •   Chris Miller

      •   Sr. Developer -- Huffington Post

      •   Twitter: @ee99ee

      •   Email: chris.miller@huffingtonpost.com
Git? Git Wha?
•   When the office git expert has to come fix everything
Git? Git Wha?
•   When the office git expert has to come fix everything
Git Background
Git Background
•   Distributed revision control system
Git Background
•   Distributed revision control system

•   Developed by Linus Torvalds for Linux kernel development
Git Background
•   Distributed revision control system

•   Developed by Linus Torvalds for Linux kernel development

•   Designed for distributed development
Git Background
•   Distributed revision control system

•   Developed by Linus Torvalds for Linux kernel development

•   Designed for distributed development

•   Designed for large projects (large codebase)
Git Repos
Git Repos
•   What is a git repository (repo)?
Git Repos
•   What is a git repository (repo)?

    •   Directory of files managed by git
Git Repos
•   What is a git repository (repo)?

    •   Directory of files managed by git

•   It contains:Your files!
Git Repos
•   What is a git repository (repo)?

    •   Directory of files managed by git

•   It contains:Your files!

•   Special .git/ directory
First Steps
First Steps
•   Download and install git client (http://git-scm.com/downloads)
First Steps
•   Download and install git client (http://git-scm.com/downloads)

•   Create the repo, add your files, and commit
First Steps
•   Download and install git client (http://git-scm.com/downloads)

•   Create the repo, add your files, and commit

    • Initializeinit repo:
           git
                 the
First Steps
•   Download and install git client (http://git-scm.com/downloads)

•   Create the repo, add your files, and commit

    • Initializeinit repo:
           git
                 the


    • Addgit add myfile.c
         your file(s):
First Steps
•   Download and install git client (http://git-scm.com/downloads)

•   Create the repo, add your files, and commit

    • Initializeinit repo:
           git
                 the


    • Addgit add myfile.c
         your file(s):


    • Commit!:
         git commit -m “I haz filez! yay!”
Git Client
When someone says a git GUI is better than the command line?
Git Client
When someone says a git GUI is better than the command line?
The Basics
The Basics
•   Git repositories are local
The Basics
•   Git repositories are local

    •   Repositories are relative to your working environment (not the server)
The Basics
•   Git repositories are local

    •   Repositories are relative to your working environment (not the server)

•   A commit goes to your local repository -- not some server (as in SVN)
The Basics
•   Git repositories are local

    •   Repositories are relative to your working environment (not the server)

•   A commit goes to your local repository -- not some server (as in SVN)

•   A commit is a snapshot -- A point in time
The Basics
•   Git repositories are local

    •   Repositories are relative to your working environment (not the server)

•   A commit goes to your local repository -- not some server (as in SVN)

•   A commit is a snapshot -- A point in time

•   Commits are metadata about the commit before and changes now
Cloning
•   To get a remote repo, you need the URL

    •   git clone [url]
The Index
•   The index tracks what you want to commit

•   Files are in one of three states

    •   Tracked

    •   Ignored

    •   Untracked
Staging and Committing
•   Untracked files are “staged” prior to a commit
Staging and Committing
•   Untracked files are “staged” prior to a commit
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Untracked files:
     # (use "git add <file>..." to include in what will be committed)
     #
     #
     test.c
     nothing added to commit but untracked files present (use "git add" to track)
Staging and Committing
•   Untracked files are “staged” prior to a commit
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Untracked files:
     # (use "git add <file>..." to include in what will be committed)
     #
     #
     test.c
     nothing added to commit but untracked files present (use "git add" to track)
     [~/domains/gittalk]$ git add test.c
Staging and Committing
•   Untracked files are “staged” prior to a commit
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Untracked files:
     # (use "git add <file>..." to include in what will be committed)
     #
     #
     test.c
     nothing added to commit but untracked files present (use "git add" to track)
     [~/domains/gittalk]$ git add test.c
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Changes to be committed:
     # (use "git rm --cached <file>..." to unstage)
     #
     #
     new file: test.c
     #
Staging and Committing
•   Untracked files are “staged” prior to a commit
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Untracked files:
     # (use "git add <file>..." to include in what will be committed)
     #
     #
     test.c
     nothing added to commit but untracked files present (use "git add" to track)
     [~/domains/gittalk]$ git add test.c
     [~/domains/gittalk]$ git status
     # On branch master
     #
     # Initial commit
     #
     # Changes to be committed:
     # (use "git rm --cached <file>..." to unstage)
     #
     #
     new file: test.c
     #
     [~/domains/gittalk]$ git commit -m “I haz moar codez”
     [master (root-commit) 3e44a84] I haz moar codez
      1 file changed, 1 insertion(+)
      create mode 100644 test.c
Removing and Moving
•   Removing a file from the file system is not enough.

•   You must tell git to remove from the repo as well (and commit that change)
Removing and Moving
•   Removing a file from the file system is not enough.

•   You must tell git to remove from the repo as well (and commit that change)
          [~/domains/gittalk]$ git rm test.c
          rm 'test.c'


          [~/domains/gittalk]$ git status
          # On branch master
          # Changes to be committed:
          # (use "git reset HEAD <file>..." to unstage)
          #
          #	

 deleted: test.c
          #

          [~/domains/gittalk]$ git commit -m "I removed a file"
          [master e993a90] I removed a file
           1 file changed, 1 deletion(-)
           delete mode 100644 test.c
Removing and Moving
•   Removing a file from the file system is not enough.

•   You must tell git to remove from the repo as well (and commit that change)
          [~/domains/gittalk]$ git rm test.c
          rm 'test.c'


          [~/domains/gittalk]$ git status
          # On branch master
          # Changes to be committed:
                                                                 •   P. S. - Moving files works the same way
          # (use "git reset HEAD <file>..." to unstage)
          #
          #	

 deleted: test.c
          #
                                                                 •   Use git mv in the same sense

          [~/domains/gittalk]$ git commit -m "I removed a file"
          [master e993a90] I removed a file
           1 file changed, 1 deletion(-)
           delete mode 100644 test.c
Ignoring Stuff
•   Tell git to ignore files with .gitignore

•   Text file located in root of git repo

•   Tracked and committed like a normal file
Ignoring Stuff                         /tmp/
                                                                    *~
                                                                    *.lock
                                                                    *.DS_Store

•   Tell git to ignore files with .gitignore                         *.swp
                                                                    *.out
                                                                    ~$*
•   Text file located in root of git repo                            [Tt]humbs.db
                                                                    /.svn/*
                                                                    */.svn/*
•   Tracked and committed like a normal file                         /CVS/*
                                                                    */CVS/*
                                                                    .cvsignore
                                                                    */.cvsignore
                                                                    .DS_Store
                          Example from Huffington Post .gitignore:   Icon?
                                                                    ._*
                                                                    .Spotlight-V100
                                                                    .Trashes
                                                                    Desktop.ini
                                                                    *.hg
                                                                    *.project
Peeking Inside
•   A single .git directory in root of project structure contains git meta data

•   Types of meta data:

    •   Blobs

    •   Trees

    •   Commits

    •   Tags
Peeking Inside
•   Blobs (Binary Large Objects) are copies of the actual files

•   A SHA1 hash of each file is made and the contents stored as a
    filename of the hash. Example:

    •   .git/objects/9da581d910c9c4ac93557ca4859e767f5caf5169
Peeking Inside
•   Blobs (Binary Large Objects) are copies of the actual files

•   A SHA1 hash of each file is made and the contents stored as a
    filename of the hash. Example:

    •   .git/objects/9da581d910c9c4ac93557ca4859e767f5caf5169

•   Each file stored only once

•   Identical files, regardless of directory, stored only once

•   SHA1 hash is identical on everyone’s machine

    •   Same file always computes to the same hash
Peeking Inside
Peeking Inside
•   Tree: Mapping of directory path, blob id, and meta info (chmod, etc.)
Peeking Inside
•   Tree: Mapping of directory path, blob id, and meta info (chmod, etc.)

•   Commit

    •   Meta data about author, comment, and tree reference

    •   Allows git to compile a complete snapshot of the tree at that given
        time
Peeking Inside
•   Tree: Mapping of directory path, blob id, and meta info (chmod, etc.)

•   Commit

    •   Meta data about author, comment, and tree reference

    •   Allows git to compile a complete snapshot of the tree at that given
        time

•   Tags: Arbitrary, user-defined pointer to a given commit. Example:

    •   Ver2.0-Alpha -> 9da581d910c9c4ac93557ca4859e767f5caf5169
The Index and Committing
      •    The index is a list of files and their blob references for the current
           state of the repo
[~/domains/HuffingtonPost/huffpost-web]$ git ls-files -s
100644 197687b4afab0816d33dcdfd68e462880bdac997 0
www/public/twitter/public_info.php
100644 0b5a713e78d33b211e334a5fe2df0d7d66eac3cb 0
 www/public/twitter/quicktwitter_suggestion.php
100644 d1ddd421d284e167079124cef22b9dd788952036 0
      www/public/twitter/track_twitter_suggestions.php
100644 89f1197c8d71064fbb4a4add6310b314c073f3cd 0
 www/public/twitter/twitter_suggestions.php
100644 7f57b7ac131aed04832034dc76c59ab30a92f020 0
 www/public/typekey/regkey.txt
100644 3a4bec59ae14a44834ef6dfeb1cc26a19a62d24d 0
 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Dl.inc.php
100644 32e8b6a04ae8284288133764e62f7a067b63cf08 0
www/public/uk-celebrity/includes/modules/ukCeleb_mod_FeaturedBlogs.inc.php
100644 89e0386b2dffcf0f105280017d27367269a899d0 0
 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Photos.inc.php
100644 91db4907100cd15728de94e5951900d2cdc91330 0
      www/public/uk-celebrity/includes/modules/
ukCeleb_mod_RRailModules.inc.php
(....)
The Index and Committing
      •    The index is a list of files and their blob references for the current
           state of the repo
[~/domains/HuffingtonPost/huffpost-web]$ git ls-files -s
100644 197687b4afab0816d33dcdfd68e462880bdac997 0
www/public/twitter/public_info.php
100644 0b5a713e78d33b211e334a5fe2df0d7d66eac3cb 0
 www/public/twitter/quicktwitter_suggestion.php
100644 d1ddd421d284e167079124cef22b9dd788952036 0
      www/public/twitter/track_twitter_suggestions.php
100644 89f1197c8d71064fbb4a4add6310b314c073f3cd 0
 www/public/twitter/twitter_suggestions.php
100644 7f57b7ac131aed04832034dc76c59ab30a92f020 0
 www/public/typekey/regkey.txt
100644 3a4bec59ae14a44834ef6dfeb1cc26a19a62d24d 0
 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Dl.inc.php
100644 32e8b6a04ae8284288133764e62f7a067b63cf08 0
www/public/uk-celebrity/includes/modules/ukCeleb_mod_FeaturedBlogs.inc.php
100644 89e0386b2dffcf0f105280017d27367269a899d0 0
 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Photos.inc.php
100644 91db4907100cd15728de94e5951900d2cdc91330 0
      www/public/uk-celebrity/includes/modules/
ukCeleb_mod_RRailModules.inc.php
(....)



      •   Tip: To keep things brief, sometimes only the prefix is used. To lookup
          the full commit id:
      [~/domains/HuffingtonPost/huffpost-web]$ git rev-parse 3b18e512d
      3b18e512dba79e4c8300dd08aeb37f8e728b8dad
Committing: One more thing
•   Commit often



•   When in doubt, commit



•   Commit often -- no, really
Branching
•   Fundamental way to create a separate line of development

•   Segment development of multiple features/bug fixes concurrently
    without one affecting the other

•   When in doubt, branch
Branching
•   Fundamental way to create a separate line of development

•   Segment development of multiple features/bug fixes concurrently
    without one affecting the other

•   When in doubt, branch

•   Tip: I create a branch for every JIRA ticket and name it the ticket ID
Branching
Branching


•   Create a new branch:
      [~/domains/gittalk]$ git checkout -b MyFirstBranch
      Switched to a new branch 'MyFirstBranch'
Branching


•   Create a new branch:
      [~/domains/gittalk]$ git checkout -b MyFirstBranch
      Switched to a new branch 'MyFirstBranch'

•   See what branch you are on:
      [~/domains/gittalk]$ git branch
      * MyFirstBranch
       master
Branching


•   Create a new branch:
      [~/domains/gittalk]$ git checkout -b MyFirstBranch
      Switched to a new branch 'MyFirstBranch'

•   See what branch you are on:
      [~/domains/gittalk]$ git branch
      * MyFirstBranch
       master


•   Switch branches
      [~/domains/gittalk]$ git checkout master
      Switched to branch 'master'
      [~/domains/gittalk]$ git branch
       MyFirstBranch
      * master
Sharing: I haz codez
Sharing: I haz codez
•   Git has no central repo -- Your working directory is a repo
Sharing: I haz codez
•   Git has no central repo -- Your working directory is a repo

•   Collaboration is done by “pushing” and “pulling” repos

    •   A push is syncing changes in your repo to a remote repo

    •   A pull is integrating changes to your repo from a remote repo
Collaborating
•   When a coworker and I are working on the same branch:
Collaborating
•   When a coworker and I are working on the same branch:
Remote Repos
•   Any repo can be defined as a remote repo

•   When you “clone” a repo, that repo is automatically added as a
    remote repo called “origin”
Remote Repos
•   Any repo can be defined as a remote repo

•   When you “clone” a repo, that repo is automatically added as a
    remote repo called “origin”
•   You can view remote repos and add more:
     [~/huffpost-web]$ git remote add menachem git@github.com:menachemd/huffpost-web.git

     [~/huffpost-web]$ git remote -v
     origin
 git@github.com:ee99ee/huffpost-web.git (fetch)
     origin
 git@github.com:ee99ee/huffpost-web.git (push)
     menachem
 git@github.com:menachemd/huffpost-web.git (fetch)
     menachem
 git@github.com:menachemd/huffpost-web.git (push)
     upstream
   git@github.com:huffingtonpost/huffpost-web.git (push)
     upstream
   git@github.com:huffingtonpost/huffpost-web.git (fetch)
Pulling: Fetching & Merging
Pulling: Fetching & Merging
[~/huffpost-web]$ git fetch upstream
remote: Counting objects: 985, done.
remote: Compressing objects: 100% (235/235), done.
remote: Total 630 (delta 467), reused 539 (delta 381)
Receiving objects: 100% (630/630), 89.97 KiB, done.
Resolving deltas: 100% (467/467), completed with 173 local objects.
From github.com:huffingtonpost/huffpost-web
  b6a5a33..95d0749 master        -> upstream/master
 * [new tag]      20121107_174505 -> 20121107_174505
From github.com:huffingtonpost/huffpost-web
 * [new tag]      20121107_165653 -> 20121107_165653
 * [new tag]      20121107_171309 -> 20121107_171309
Pulling: Fetching & Merging
[~/huffpost-web]$ git fetch upstream
remote: Counting objects: 985, done.
remote: Compressing objects: 100% (235/235), done.
remote: Total 630 (delta 467), reused 539 (delta 381)
Receiving objects: 100% (630/630), 89.97 KiB, done.
Resolving deltas: 100% (467/467), completed with 173 local objects.
From github.com:huffingtonpost/huffpost-web
  b6a5a33..95d0749 master        -> upstream/master
 * [new tag]      20121107_174505 -> 20121107_174505
From github.com:huffingtonpost/huffpost-web
 * [new tag]      20121107_165653 -> 20121107_165653
 * [new tag]      20121107_171309 -> 20121107_171309


[~/huffpost-web]$ git diff --summary upstream/master
 delete mode 100644 www/blogger/photofeed/script.js
 delete mode 100644 www/blogger/photofeed/style.css
 create mode 100644 www/editorial/_slideshows/helpers/5min.php
 delete mode 100644 www/editorial/commercial/cam_builder/images/trackpix.png
 delete mode 100644 www/editorial/commercial/cam_builder/js_script/modules/tracking_pixel.js
 (...)
Pulling: Fetching & Merging
[~/huffpost-web]$ git fetch upstream
remote: Counting objects: 985, done.
remote: Compressing objects: 100% (235/235), done.
remote: Total 630 (delta 467), reused 539 (delta 381)
Receiving objects: 100% (630/630), 89.97 KiB, done.
Resolving deltas: 100% (467/467), completed with 173 local objects.
From github.com:huffingtonpost/huffpost-web
  b6a5a33..95d0749 master        -> upstream/master
 * [new tag]      20121107_174505 -> 20121107_174505
From github.com:huffingtonpost/huffpost-web
 * [new tag]      20121107_165653 -> 20121107_165653
 * [new tag]      20121107_171309 -> 20121107_171309


[~/huffpost-web]$ git diff --summary upstream/master
 delete mode 100644 www/blogger/photofeed/script.js
 delete mode 100644 www/blogger/photofeed/style.css
 create mode 100644 www/editorial/_slideshows/helpers/5min.php
 delete mode 100644 www/editorial/commercial/cam_builder/images/trackpix.png
 delete mode 100644 www/editorial/commercial/cam_builder/js_script/modules/tracking_pixel.js
 (...)


[~/huffpost-web]$ git merge upstream/master
Updating 41242d4..95d0749
Fast-forward
 .gitignore                        | 1+
 conf/apns_cert.pem                   | 60 +-
 conf/apns_key.pem                    | 50 +-
 (...)
Pulling
•   The git pull command can be used to
    do git fetch + git merge automagically

•   I like to see what is going to merge
    before it does, so I use git fetch + git
    merge
Pulling
•   Repos can get big... but, there is only one copy of each unique file
Pulling
• Repos can get big... but, there is only one copy of each unique file
• How I feel when I fetch big repos:
Pulling
• Repos can get big... but, there is only one copy of each unique file
• How I feel when I fetch big repos:
Ye Olde Rebase
Ye Olde Rebase
•   Git maintains a history of every commit
Ye Olde Rebase
•   Git maintains a history of every commit

•   A merge creates a new commit point and adds changes to the end of
    the log
Ye Olde Rebase
•   Git maintains a history of every commit

•   A merge creates a new commit point and adds changes to the end of
    the log

•   Git rebase rewrites the log -- it rewrites history

                         Use with caution
                        (but don’t avoid all together)
Pushing
•   To send code to a remote repo, push:
              [~/huffpo-web]$ git push remote_name my_branch

•   Remember to commit before pushing
Pushing
•   To send code to a remote repo, push:
              [~/huffpo-web]$ git push remote_name my_branch

•   Remember to commit before pushing

    When I push before committing:
Github
•   If using github, you can issue “pull requests” to other users requesting
    they integrate your changes
Pull Requests
•   The owner of the repo to whom you send the pull request can then
    merge your changes with theirs

    •   This merge can be done on github.com if no conflicts exist

    •   If conflict exists, a git fetch and git merge is necessary (by
        them)
Pull Requests
(Or they can ignore your pull request)
Questions?
One More Funny...
How I feel when someone submits an IE6 bug report
One More Funny...
How I feel when someone submits an IE6 bug report

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commands
 
Git - a powerful version control tool
Git - a powerful version control toolGit - a powerful version control tool
Git - a powerful version control tool
 
Git and Github
Git and GithubGit and Github
Git and Github
 
git and github
git and githubgit and github
git and github
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
The git
The gitThe git
The git
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
 
Git: from Novice to Expert
Git: from Novice to ExpertGit: from Novice to Expert
Git: from Novice to Expert
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 

Similar a Gitting the Most From Git

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

Similar a Gitting the Most From Git (20)

Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Github basics
Github basicsGithub basics
Github basics
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
Basic Git commands
Basic Git commandsBasic Git commands
Basic Git commands
 
Git presentation
Git presentationGit presentation
Git presentation
 
11 git version control
11 git version control11 git version control
11 git version control
 
Source control management
Source control managementSource control management
Source control management
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git training v10
Git training v10Git training v10
Git training v10
 
Distributed Developer Workflows using Git
Distributed Developer Workflows using GitDistributed Developer Workflows using Git
Distributed Developer Workflows using Git
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
 

Último

Último (20)

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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 

Gitting the Most From Git

  • 2. Gitting the Most From Git
  • 3. Who am I? • For the people in the room: • You know me • Everyone else: • Chris Miller • Sr. Developer -- Huffington Post • Twitter: @ee99ee • Email: chris.miller@huffingtonpost.com
  • 4. Git? Git Wha? • When the office git expert has to come fix everything
  • 5. Git? Git Wha? • When the office git expert has to come fix everything
  • 7. Git Background • Distributed revision control system
  • 8. Git Background • Distributed revision control system • Developed by Linus Torvalds for Linux kernel development
  • 9. Git Background • Distributed revision control system • Developed by Linus Torvalds for Linux kernel development • Designed for distributed development
  • 10. Git Background • Distributed revision control system • Developed by Linus Torvalds for Linux kernel development • Designed for distributed development • Designed for large projects (large codebase)
  • 12. Git Repos • What is a git repository (repo)?
  • 13. Git Repos • What is a git repository (repo)? • Directory of files managed by git
  • 14. Git Repos • What is a git repository (repo)? • Directory of files managed by git • It contains:Your files!
  • 15. Git Repos • What is a git repository (repo)? • Directory of files managed by git • It contains:Your files! • Special .git/ directory
  • 17. First Steps • Download and install git client (http://git-scm.com/downloads)
  • 18. First Steps • Download and install git client (http://git-scm.com/downloads) • Create the repo, add your files, and commit
  • 19. First Steps • Download and install git client (http://git-scm.com/downloads) • Create the repo, add your files, and commit • Initializeinit repo: git the
  • 20. First Steps • Download and install git client (http://git-scm.com/downloads) • Create the repo, add your files, and commit • Initializeinit repo: git the • Addgit add myfile.c your file(s):
  • 21. First Steps • Download and install git client (http://git-scm.com/downloads) • Create the repo, add your files, and commit • Initializeinit repo: git the • Addgit add myfile.c your file(s): • Commit!: git commit -m “I haz filez! yay!”
  • 22. Git Client When someone says a git GUI is better than the command line?
  • 23. Git Client When someone says a git GUI is better than the command line?
  • 25. The Basics • Git repositories are local
  • 26. The Basics • Git repositories are local • Repositories are relative to your working environment (not the server)
  • 27. The Basics • Git repositories are local • Repositories are relative to your working environment (not the server) • A commit goes to your local repository -- not some server (as in SVN)
  • 28. The Basics • Git repositories are local • Repositories are relative to your working environment (not the server) • A commit goes to your local repository -- not some server (as in SVN) • A commit is a snapshot -- A point in time
  • 29. The Basics • Git repositories are local • Repositories are relative to your working environment (not the server) • A commit goes to your local repository -- not some server (as in SVN) • A commit is a snapshot -- A point in time • Commits are metadata about the commit before and changes now
  • 30. Cloning • To get a remote repo, you need the URL • git clone [url]
  • 31. The Index • The index tracks what you want to commit • Files are in one of three states • Tracked • Ignored • Untracked
  • 32. Staging and Committing • Untracked files are “staged” prior to a commit
  • 33. Staging and Committing • Untracked files are “staged” prior to a commit [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test.c nothing added to commit but untracked files present (use "git add" to track)
  • 34. Staging and Committing • Untracked files are “staged” prior to a commit [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test.c nothing added to commit but untracked files present (use "git add" to track) [~/domains/gittalk]$ git add test.c
  • 35. Staging and Committing • Untracked files are “staged” prior to a commit [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test.c nothing added to commit but untracked files present (use "git add" to track) [~/domains/gittalk]$ git add test.c [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: test.c #
  • 36. Staging and Committing • Untracked files are “staged” prior to a commit [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test.c nothing added to commit but untracked files present (use "git add" to track) [~/domains/gittalk]$ git add test.c [~/domains/gittalk]$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: test.c # [~/domains/gittalk]$ git commit -m “I haz moar codez” [master (root-commit) 3e44a84] I haz moar codez 1 file changed, 1 insertion(+) create mode 100644 test.c
  • 37. Removing and Moving • Removing a file from the file system is not enough. • You must tell git to remove from the repo as well (and commit that change)
  • 38. Removing and Moving • Removing a file from the file system is not enough. • You must tell git to remove from the repo as well (and commit that change) [~/domains/gittalk]$ git rm test.c rm 'test.c' [~/domains/gittalk]$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: test.c # [~/domains/gittalk]$ git commit -m "I removed a file" [master e993a90] I removed a file 1 file changed, 1 deletion(-) delete mode 100644 test.c
  • 39. Removing and Moving • Removing a file from the file system is not enough. • You must tell git to remove from the repo as well (and commit that change) [~/domains/gittalk]$ git rm test.c rm 'test.c' [~/domains/gittalk]$ git status # On branch master # Changes to be committed: • P. S. - Moving files works the same way # (use "git reset HEAD <file>..." to unstage) # # deleted: test.c # • Use git mv in the same sense [~/domains/gittalk]$ git commit -m "I removed a file" [master e993a90] I removed a file 1 file changed, 1 deletion(-) delete mode 100644 test.c
  • 40. Ignoring Stuff • Tell git to ignore files with .gitignore • Text file located in root of git repo • Tracked and committed like a normal file
  • 41. Ignoring Stuff /tmp/ *~ *.lock *.DS_Store • Tell git to ignore files with .gitignore *.swp *.out ~$* • Text file located in root of git repo [Tt]humbs.db /.svn/* */.svn/* • Tracked and committed like a normal file /CVS/* */CVS/* .cvsignore */.cvsignore .DS_Store Example from Huffington Post .gitignore: Icon? ._* .Spotlight-V100 .Trashes Desktop.ini *.hg *.project
  • 42. Peeking Inside • A single .git directory in root of project structure contains git meta data • Types of meta data: • Blobs • Trees • Commits • Tags
  • 43. Peeking Inside • Blobs (Binary Large Objects) are copies of the actual files • A SHA1 hash of each file is made and the contents stored as a filename of the hash. Example: • .git/objects/9da581d910c9c4ac93557ca4859e767f5caf5169
  • 44. Peeking Inside • Blobs (Binary Large Objects) are copies of the actual files • A SHA1 hash of each file is made and the contents stored as a filename of the hash. Example: • .git/objects/9da581d910c9c4ac93557ca4859e767f5caf5169 • Each file stored only once • Identical files, regardless of directory, stored only once • SHA1 hash is identical on everyone’s machine • Same file always computes to the same hash
  • 46. Peeking Inside • Tree: Mapping of directory path, blob id, and meta info (chmod, etc.)
  • 47. Peeking Inside • Tree: Mapping of directory path, blob id, and meta info (chmod, etc.) • Commit • Meta data about author, comment, and tree reference • Allows git to compile a complete snapshot of the tree at that given time
  • 48. Peeking Inside • Tree: Mapping of directory path, blob id, and meta info (chmod, etc.) • Commit • Meta data about author, comment, and tree reference • Allows git to compile a complete snapshot of the tree at that given time • Tags: Arbitrary, user-defined pointer to a given commit. Example: • Ver2.0-Alpha -> 9da581d910c9c4ac93557ca4859e767f5caf5169
  • 49. The Index and Committing • The index is a list of files and their blob references for the current state of the repo [~/domains/HuffingtonPost/huffpost-web]$ git ls-files -s 100644 197687b4afab0816d33dcdfd68e462880bdac997 0 www/public/twitter/public_info.php 100644 0b5a713e78d33b211e334a5fe2df0d7d66eac3cb 0 www/public/twitter/quicktwitter_suggestion.php 100644 d1ddd421d284e167079124cef22b9dd788952036 0 www/public/twitter/track_twitter_suggestions.php 100644 89f1197c8d71064fbb4a4add6310b314c073f3cd 0 www/public/twitter/twitter_suggestions.php 100644 7f57b7ac131aed04832034dc76c59ab30a92f020 0 www/public/typekey/regkey.txt 100644 3a4bec59ae14a44834ef6dfeb1cc26a19a62d24d 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Dl.inc.php 100644 32e8b6a04ae8284288133764e62f7a067b63cf08 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_FeaturedBlogs.inc.php 100644 89e0386b2dffcf0f105280017d27367269a899d0 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Photos.inc.php 100644 91db4907100cd15728de94e5951900d2cdc91330 0 www/public/uk-celebrity/includes/modules/ ukCeleb_mod_RRailModules.inc.php (....)
  • 50. The Index and Committing • The index is a list of files and their blob references for the current state of the repo [~/domains/HuffingtonPost/huffpost-web]$ git ls-files -s 100644 197687b4afab0816d33dcdfd68e462880bdac997 0 www/public/twitter/public_info.php 100644 0b5a713e78d33b211e334a5fe2df0d7d66eac3cb 0 www/public/twitter/quicktwitter_suggestion.php 100644 d1ddd421d284e167079124cef22b9dd788952036 0 www/public/twitter/track_twitter_suggestions.php 100644 89f1197c8d71064fbb4a4add6310b314c073f3cd 0 www/public/twitter/twitter_suggestions.php 100644 7f57b7ac131aed04832034dc76c59ab30a92f020 0 www/public/typekey/regkey.txt 100644 3a4bec59ae14a44834ef6dfeb1cc26a19a62d24d 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Dl.inc.php 100644 32e8b6a04ae8284288133764e62f7a067b63cf08 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_FeaturedBlogs.inc.php 100644 89e0386b2dffcf0f105280017d27367269a899d0 0 www/public/uk-celebrity/includes/modules/ukCeleb_mod_Photos.inc.php 100644 91db4907100cd15728de94e5951900d2cdc91330 0 www/public/uk-celebrity/includes/modules/ ukCeleb_mod_RRailModules.inc.php (....) • Tip: To keep things brief, sometimes only the prefix is used. To lookup the full commit id: [~/domains/HuffingtonPost/huffpost-web]$ git rev-parse 3b18e512d 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
  • 51. Committing: One more thing • Commit often • When in doubt, commit • Commit often -- no, really
  • 52. Branching • Fundamental way to create a separate line of development • Segment development of multiple features/bug fixes concurrently without one affecting the other • When in doubt, branch
  • 53. Branching • Fundamental way to create a separate line of development • Segment development of multiple features/bug fixes concurrently without one affecting the other • When in doubt, branch • Tip: I create a branch for every JIRA ticket and name it the ticket ID
  • 55. Branching • Create a new branch: [~/domains/gittalk]$ git checkout -b MyFirstBranch Switched to a new branch 'MyFirstBranch'
  • 56. Branching • Create a new branch: [~/domains/gittalk]$ git checkout -b MyFirstBranch Switched to a new branch 'MyFirstBranch' • See what branch you are on: [~/domains/gittalk]$ git branch * MyFirstBranch master
  • 57. Branching • Create a new branch: [~/domains/gittalk]$ git checkout -b MyFirstBranch Switched to a new branch 'MyFirstBranch' • See what branch you are on: [~/domains/gittalk]$ git branch * MyFirstBranch master • Switch branches [~/domains/gittalk]$ git checkout master Switched to branch 'master' [~/domains/gittalk]$ git branch MyFirstBranch * master
  • 58. Sharing: I haz codez
  • 59. Sharing: I haz codez • Git has no central repo -- Your working directory is a repo
  • 60. Sharing: I haz codez • Git has no central repo -- Your working directory is a repo • Collaboration is done by “pushing” and “pulling” repos • A push is syncing changes in your repo to a remote repo • A pull is integrating changes to your repo from a remote repo
  • 61. Collaborating • When a coworker and I are working on the same branch:
  • 62. Collaborating • When a coworker and I are working on the same branch:
  • 63. Remote Repos • Any repo can be defined as a remote repo • When you “clone” a repo, that repo is automatically added as a remote repo called “origin”
  • 64. Remote Repos • Any repo can be defined as a remote repo • When you “clone” a repo, that repo is automatically added as a remote repo called “origin” • You can view remote repos and add more: [~/huffpost-web]$ git remote add menachem git@github.com:menachemd/huffpost-web.git [~/huffpost-web]$ git remote -v origin git@github.com:ee99ee/huffpost-web.git (fetch) origin git@github.com:ee99ee/huffpost-web.git (push) menachem git@github.com:menachemd/huffpost-web.git (fetch) menachem git@github.com:menachemd/huffpost-web.git (push) upstream git@github.com:huffingtonpost/huffpost-web.git (push) upstream git@github.com:huffingtonpost/huffpost-web.git (fetch)
  • 66. Pulling: Fetching & Merging [~/huffpost-web]$ git fetch upstream remote: Counting objects: 985, done. remote: Compressing objects: 100% (235/235), done. remote: Total 630 (delta 467), reused 539 (delta 381) Receiving objects: 100% (630/630), 89.97 KiB, done. Resolving deltas: 100% (467/467), completed with 173 local objects. From github.com:huffingtonpost/huffpost-web b6a5a33..95d0749 master -> upstream/master * [new tag] 20121107_174505 -> 20121107_174505 From github.com:huffingtonpost/huffpost-web * [new tag] 20121107_165653 -> 20121107_165653 * [new tag] 20121107_171309 -> 20121107_171309
  • 67. Pulling: Fetching & Merging [~/huffpost-web]$ git fetch upstream remote: Counting objects: 985, done. remote: Compressing objects: 100% (235/235), done. remote: Total 630 (delta 467), reused 539 (delta 381) Receiving objects: 100% (630/630), 89.97 KiB, done. Resolving deltas: 100% (467/467), completed with 173 local objects. From github.com:huffingtonpost/huffpost-web b6a5a33..95d0749 master -> upstream/master * [new tag] 20121107_174505 -> 20121107_174505 From github.com:huffingtonpost/huffpost-web * [new tag] 20121107_165653 -> 20121107_165653 * [new tag] 20121107_171309 -> 20121107_171309 [~/huffpost-web]$ git diff --summary upstream/master delete mode 100644 www/blogger/photofeed/script.js delete mode 100644 www/blogger/photofeed/style.css create mode 100644 www/editorial/_slideshows/helpers/5min.php delete mode 100644 www/editorial/commercial/cam_builder/images/trackpix.png delete mode 100644 www/editorial/commercial/cam_builder/js_script/modules/tracking_pixel.js (...)
  • 68. Pulling: Fetching & Merging [~/huffpost-web]$ git fetch upstream remote: Counting objects: 985, done. remote: Compressing objects: 100% (235/235), done. remote: Total 630 (delta 467), reused 539 (delta 381) Receiving objects: 100% (630/630), 89.97 KiB, done. Resolving deltas: 100% (467/467), completed with 173 local objects. From github.com:huffingtonpost/huffpost-web b6a5a33..95d0749 master -> upstream/master * [new tag] 20121107_174505 -> 20121107_174505 From github.com:huffingtonpost/huffpost-web * [new tag] 20121107_165653 -> 20121107_165653 * [new tag] 20121107_171309 -> 20121107_171309 [~/huffpost-web]$ git diff --summary upstream/master delete mode 100644 www/blogger/photofeed/script.js delete mode 100644 www/blogger/photofeed/style.css create mode 100644 www/editorial/_slideshows/helpers/5min.php delete mode 100644 www/editorial/commercial/cam_builder/images/trackpix.png delete mode 100644 www/editorial/commercial/cam_builder/js_script/modules/tracking_pixel.js (...) [~/huffpost-web]$ git merge upstream/master Updating 41242d4..95d0749 Fast-forward .gitignore | 1+ conf/apns_cert.pem | 60 +- conf/apns_key.pem | 50 +- (...)
  • 69. Pulling • The git pull command can be used to do git fetch + git merge automagically • I like to see what is going to merge before it does, so I use git fetch + git merge
  • 70. Pulling • Repos can get big... but, there is only one copy of each unique file
  • 71. Pulling • Repos can get big... but, there is only one copy of each unique file • How I feel when I fetch big repos:
  • 72. Pulling • Repos can get big... but, there is only one copy of each unique file • How I feel when I fetch big repos:
  • 74. Ye Olde Rebase • Git maintains a history of every commit
  • 75. Ye Olde Rebase • Git maintains a history of every commit • A merge creates a new commit point and adds changes to the end of the log
  • 76. Ye Olde Rebase • Git maintains a history of every commit • A merge creates a new commit point and adds changes to the end of the log • Git rebase rewrites the log -- it rewrites history Use with caution (but don’t avoid all together)
  • 77. Pushing • To send code to a remote repo, push: [~/huffpo-web]$ git push remote_name my_branch • Remember to commit before pushing
  • 78. Pushing • To send code to a remote repo, push: [~/huffpo-web]$ git push remote_name my_branch • Remember to commit before pushing When I push before committing:
  • 79. Github • If using github, you can issue “pull requests” to other users requesting they integrate your changes
  • 80. Pull Requests • The owner of the repo to whom you send the pull request can then merge your changes with theirs • This merge can be done on github.com if no conflicts exist • If conflict exists, a git fetch and git merge is necessary (by them)
  • 81. Pull Requests (Or they can ignore your pull request)
  • 83. One More Funny... How I feel when someone submits an IE6 bug report
  • 84. One More Funny... How I feel when someone submits an IE6 bug report

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n