SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of troubleJon Senchyna
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
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 commandsth507
 
Git - a powerful version control tool
Git - a powerful version control toolGit - a powerful version control tool
Git - a powerful version control toolKuo-Le Mei
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advancedYodalee
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails UndergroundAriejan de Vroom
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
 
Git: from Novice to Expert
Git: from Novice to ExpertGit: from Novice to Expert
Git: from Novice to ExpertGoddy Zhao
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 

Mais procurados (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
 

Semelhante a Gitting the Most From Git

Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.comdropsolid
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
Basic Git commands
Basic Git commandsBasic Git commands
Basic Git commandsJitendra Zaa
 
11 git version control
11 git version control11 git version control
11 git version controlWasim Alatrash
 
Source control management
Source control managementSource control management
Source control managementOwen Winkler
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to GitMuhil Vannan
 
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 GitGeoff Hoffman
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxAbdul Salam
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
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 levelsGorav Singal
 
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 GitRobert Lee-Cann
 
Distributed Developer Workflows using Git
Distributed Developer Workflows using GitDistributed Developer Workflows using Git
Distributed Developer Workflows using GitSusan Potter
 

Semelhante 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 githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
 
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
 

Último

TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxNeo4j
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 

Último (20)

TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 

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 do 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