SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
keskiviikkona 28. syyskuuta 2011
Using Git
                                   Basics and workflows




keskiviikkona 28. syyskuuta 2011
Git in a nutshell
         •        Distributed revision control system with an emphasis on speed
                    •        Git does not use a centralized server (like CVS, Subversion)
         •        Developed by Linus Torvalds on 2005 for maintenance of Linux
                  kernel development
                    •        “I name all my projects after myself. First Linux, now Git.”
                             ('git' is British slang for stupid, childish person)
                    •        “Take CVS as an example of what NOT to do”
         •        Goals
                    •        Very high performance
                    •        Simple design (“Git is a stupid content tracker” as Linus says)
                    •        Strong support for non-linear development (branches)
                    •        Fully distributed workflow
                    •        Able to handle large projects (like Linux kernel)


keskiviikkona 28. syyskuuta 2011
Version Control Systems
                                   A brief history




keskiviikkona 28. syyskuuta 2011
Local VCS
         •        First generation of Version Control Systems
         •        Local database to handle versions
         •        No collaboration between developers




keskiviikkona 28. syyskuuta 2011
Centralized VCS
         •        Single server contains all the versioned files
                    •        CVS, Subversion
         •        Advantages
                    •        Everyone knows everyone else progress
                    •        Easier to administer
         •        Downsides
                    •        Single point of failure




keskiviikkona 28. syyskuuta 2011
Distributed VCS
         •        Clients fully mirror the repository
                    •        All revision data lies in .git directories
                    •        Git, Mercurial, Bazaar
         •        Advantages
                    •        Every checkout is really a full
                             backup of all the data
                    •        Parallel workflows within
                             the same project
         •        Downsides
                    •        Not (yet!) ;-)




keskiviikkona 28. syyskuuta 2011
Using Git
                                     Concept




keskiviikkona 28. syyskuuta 2011
Git vs. any other CVS
         •        Other systems store data as changes to a base version of each file




         •        Git stores data as snapshots of the project over time




keskiviikkona 28. syyskuuta 2011
Git vs. Centralized CVS

         • Most operations are local
                    •        Incredible speed while doing operations
                    •        You can continue your work while been
                             offline (commit data, rollback, etc)




keskiviikkona 28. syyskuuta 2011
The Three States
         •        Files are always committed, staged or modified
         •        Can be very useful in large projects
                    •        The whole staging phase can be skipped entirely




keskiviikkona 28. syyskuuta 2011
Tracked and untracked files
         •        Each file in working copy directory (your project folder) can
                  be tracked or untracked
                    •        Tracked files can be committed (unmodified), modified or staged
                    •        Untracked files are everything else in your working copy directory
                              •    E.g. in Drupal project sites/default/settings.php would be untracked

                              •    Untracked files can be defined in .gitignore file




keskiviikkona 28. syyskuuta 2011
Using Git
                                   Basic commands




keskiviikkona 28. syyskuuta 2011
Basic commands

         Create clean git project directory

         $ git init



         In most cases (like Drupal based) clone an existing repository

         $ git clone git://git.drupal.org/project/drupal.git myfolder




keskiviikkona 28. syyskuuta 2011
Basic commands
         See git config

         $ git config --list

         $ git config --global user.name "Lari Vaartio"

         $ git config --global user.email "lari.vaartio@mearra.com"

         Check status of your project

         $ git status

         Check log info

         $ git log

         Check local branches and all branches (remote and local)

         $ git branch OR $ git branch -r




keskiviikkona 28. syyskuuta 2011
Creating branch
         Let’s create our own branch

         First select release (tag) you are going to use

         $ git tag

         $ git checkout DRUPAL-7-0

         Check log and branch info

         $ git log

         $ git branch

         Create new branch

         $ git checkout -b mearra




keskiviikkona 28. syyskuuta 2011
Adding files
         Let’s add some custom code

         $ drush dl addthis

         $ git status

         $ git add .

         $ git commit -m ‘added addthis module’

         $ git log

         Let’s make some modifications

         $ pico sites/all/modules/addthis/README.txt

         $ git add sites/all/modules/addthis/README.txt

         OR to skip staging entirely

         $ git commit -a -m ‘Contact information updated’



keskiviikkona 28. syyskuuta 2011
Discarding changes
         To discard changes which are staged but not committed yet

         $ git reset HEAD sites/all/modules/addthis/README.txt



         To discard changes which are modified but not staged

         $ git checkout sites/all/modules/addthis/README.txt



         To rollback previous commit grab a commit from git log

         $ git reset 521fa42e (goes to the commit but keeps files)

         OR

         $ git reset --hard 521fa42e (delete files too)




keskiviikkona 28. syyskuuta 2011
Ignoring files
         Let’s add a file which should be untracked

         $ cp sites/default/default.settings.php sites/default/
         settings.php

         $ git status

         $ echo "sites/default/settings.php" >> .gitignore

         $ git status

         $ git add .gitignore

         $ git commit -m 'gitignore file added'




keskiviikkona 28. syyskuuta 2011
Remote Repositories
         Show remote repositories

         $ git remote

         Add a new one for the project

         $ git remote add mearrarepo git@github.com:vaartio/mearrarepo.git

         $ git push <repositoryname> <branchname>

         Commit new data to remote repository

         $ git push mearrarepo mearra

         Pull data from remote repository

         $ git fetch mearrarepo mearra

         $ git pull mearrarepo mearra (fetch and merge)




keskiviikkona 28. syyskuuta 2011
Merging


         Merge new Drupal core version with mearra branch

         $ git merge CVS

         $ git log




keskiviikkona 28. syyskuuta 2011
Using Git
                                    Branching




keskiviikkona 28. syyskuuta 2011
Branching
         • Branch is a snapshot




                                   Snapshots               Commits




keskiviikkona 28. syyskuuta 2011
Branching
         $ git branch testing

         Creates a new pointer at the same commit you’re currently on.




keskiviikkona 28. syyskuuta 2011
Branching
         $ git checkout testing

         This moves HEAD to point to the testing branch.




keskiviikkona 28. syyskuuta 2011
Branching
         Make a change and commit it.

         $ vim test.rb

         $ git commit -a -m 'made a change'




keskiviikkona 28. syyskuuta 2011
Branching
         Let’s switch back to the master branch.

         $ git checkout master

         This moves HEAD to master branch and reverts the files in your
         working directory back to the snapshot that master points to.




keskiviikkona 28. syyskuuta 2011
Branching
         Let’s make changes to the master branch.

         $ vim test.rb

         $ git commit -a -m 'made other changes'




keskiviikkona 28. syyskuuta 2011
Merging branches
         Let’s merge iss53 branch to the master.

         $ git merge iss53



        Step 1                            Step 2




                             Step 3




keskiviikkona 28. syyskuuta 2011
Using Git
                                   Different workflows




keskiviikkona 28. syyskuuta 2011
Centralized Workflow
                  No differs from CVS or Subversion




keskiviikkona 28. syyskuuta 2011
Integration Manager Workflow
         1.       The project maintainer pushes to their public repository.
         2.       A contributor clones that repository and makes changes.
         3.       The contributor pushes to their own public copy.
         4.       The contributor sends the maintainer an e-mail asking them to pull changes.
         5.       The maintainer adds the contributor’s repo as a remote and merges locally.
         6.       The maintainer pushes merged changes to the main repository.




keskiviikkona 28. syyskuuta 2011
Dictator and Lieutenants Workflow
         1.       Regular developers work on their topic branch and rebase their work on top of master. The
                  master branch is that of the dictator.
         2.       Lieutenants merge the developers’ topic branches into their master branch.
         3.       The dictator merges the lieutenants’ master branches into the dictator’s master branch.
         4.       The dictator pushes their master to the reference repository so the other developers can
                  rebase on it.




keskiviikkona 28. syyskuuta 2011
Summary
         •        Git is distributed VCS
         •        Git stores snapshots not changes
         •        Nearly all operations are local and therefore
                  they are very fast
         •        Branch is a snapshot, not files in a
                  separated directory
         •        Git supports multiple remote repositories
                  which enables different workflows
         •        Git is powerful

keskiviikkona 28. syyskuuta 2011
Thanks!



keskiviikkona 28. syyskuuta 2011

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Using Git

  • 2. Using Git Basics and workflows keskiviikkona 28. syyskuuta 2011
  • 3. Git in a nutshell • Distributed revision control system with an emphasis on speed • Git does not use a centralized server (like CVS, Subversion) • Developed by Linus Torvalds on 2005 for maintenance of Linux kernel development • “I name all my projects after myself. First Linux, now Git.” ('git' is British slang for stupid, childish person) • “Take CVS as an example of what NOT to do” • Goals • Very high performance • Simple design (“Git is a stupid content tracker” as Linus says) • Strong support for non-linear development (branches) • Fully distributed workflow • Able to handle large projects (like Linux kernel) keskiviikkona 28. syyskuuta 2011
  • 4. Version Control Systems A brief history keskiviikkona 28. syyskuuta 2011
  • 5. Local VCS • First generation of Version Control Systems • Local database to handle versions • No collaboration between developers keskiviikkona 28. syyskuuta 2011
  • 6. Centralized VCS • Single server contains all the versioned files • CVS, Subversion • Advantages • Everyone knows everyone else progress • Easier to administer • Downsides • Single point of failure keskiviikkona 28. syyskuuta 2011
  • 7. Distributed VCS • Clients fully mirror the repository • All revision data lies in .git directories • Git, Mercurial, Bazaar • Advantages • Every checkout is really a full backup of all the data • Parallel workflows within the same project • Downsides • Not (yet!) ;-) keskiviikkona 28. syyskuuta 2011
  • 8. Using Git Concept keskiviikkona 28. syyskuuta 2011
  • 9. Git vs. any other CVS • Other systems store data as changes to a base version of each file • Git stores data as snapshots of the project over time keskiviikkona 28. syyskuuta 2011
  • 10. Git vs. Centralized CVS • Most operations are local • Incredible speed while doing operations • You can continue your work while been offline (commit data, rollback, etc) keskiviikkona 28. syyskuuta 2011
  • 11. The Three States • Files are always committed, staged or modified • Can be very useful in large projects • The whole staging phase can be skipped entirely keskiviikkona 28. syyskuuta 2011
  • 12. Tracked and untracked files • Each file in working copy directory (your project folder) can be tracked or untracked • Tracked files can be committed (unmodified), modified or staged • Untracked files are everything else in your working copy directory • E.g. in Drupal project sites/default/settings.php would be untracked • Untracked files can be defined in .gitignore file keskiviikkona 28. syyskuuta 2011
  • 13. Using Git Basic commands keskiviikkona 28. syyskuuta 2011
  • 14. Basic commands Create clean git project directory $ git init In most cases (like Drupal based) clone an existing repository $ git clone git://git.drupal.org/project/drupal.git myfolder keskiviikkona 28. syyskuuta 2011
  • 15. Basic commands See git config $ git config --list $ git config --global user.name "Lari Vaartio" $ git config --global user.email "lari.vaartio@mearra.com" Check status of your project $ git status Check log info $ git log Check local branches and all branches (remote and local) $ git branch OR $ git branch -r keskiviikkona 28. syyskuuta 2011
  • 16. Creating branch Let’s create our own branch First select release (tag) you are going to use $ git tag $ git checkout DRUPAL-7-0 Check log and branch info $ git log $ git branch Create new branch $ git checkout -b mearra keskiviikkona 28. syyskuuta 2011
  • 17. Adding files Let’s add some custom code $ drush dl addthis $ git status $ git add . $ git commit -m ‘added addthis module’ $ git log Let’s make some modifications $ pico sites/all/modules/addthis/README.txt $ git add sites/all/modules/addthis/README.txt OR to skip staging entirely $ git commit -a -m ‘Contact information updated’ keskiviikkona 28. syyskuuta 2011
  • 18. Discarding changes To discard changes which are staged but not committed yet $ git reset HEAD sites/all/modules/addthis/README.txt To discard changes which are modified but not staged $ git checkout sites/all/modules/addthis/README.txt To rollback previous commit grab a commit from git log $ git reset 521fa42e (goes to the commit but keeps files) OR $ git reset --hard 521fa42e (delete files too) keskiviikkona 28. syyskuuta 2011
  • 19. Ignoring files Let’s add a file which should be untracked $ cp sites/default/default.settings.php sites/default/ settings.php $ git status $ echo "sites/default/settings.php" >> .gitignore $ git status $ git add .gitignore $ git commit -m 'gitignore file added' keskiviikkona 28. syyskuuta 2011
  • 20. Remote Repositories Show remote repositories $ git remote Add a new one for the project $ git remote add mearrarepo git@github.com:vaartio/mearrarepo.git $ git push <repositoryname> <branchname> Commit new data to remote repository $ git push mearrarepo mearra Pull data from remote repository $ git fetch mearrarepo mearra $ git pull mearrarepo mearra (fetch and merge) keskiviikkona 28. syyskuuta 2011
  • 21. Merging Merge new Drupal core version with mearra branch $ git merge CVS $ git log keskiviikkona 28. syyskuuta 2011
  • 22. Using Git Branching keskiviikkona 28. syyskuuta 2011
  • 23. Branching • Branch is a snapshot Snapshots Commits keskiviikkona 28. syyskuuta 2011
  • 24. Branching $ git branch testing Creates a new pointer at the same commit you’re currently on. keskiviikkona 28. syyskuuta 2011
  • 25. Branching $ git checkout testing This moves HEAD to point to the testing branch. keskiviikkona 28. syyskuuta 2011
  • 26. Branching Make a change and commit it. $ vim test.rb $ git commit -a -m 'made a change' keskiviikkona 28. syyskuuta 2011
  • 27. Branching Let’s switch back to the master branch. $ git checkout master This moves HEAD to master branch and reverts the files in your working directory back to the snapshot that master points to. keskiviikkona 28. syyskuuta 2011
  • 28. Branching Let’s make changes to the master branch. $ vim test.rb $ git commit -a -m 'made other changes' keskiviikkona 28. syyskuuta 2011
  • 29. Merging branches Let’s merge iss53 branch to the master. $ git merge iss53 Step 1 Step 2 Step 3 keskiviikkona 28. syyskuuta 2011
  • 30. Using Git Different workflows keskiviikkona 28. syyskuuta 2011
  • 31. Centralized Workflow No differs from CVS or Subversion keskiviikkona 28. syyskuuta 2011
  • 32. Integration Manager Workflow 1. The project maintainer pushes to their public repository. 2. A contributor clones that repository and makes changes. 3. The contributor pushes to their own public copy. 4. The contributor sends the maintainer an e-mail asking them to pull changes. 5. The maintainer adds the contributor’s repo as a remote and merges locally. 6. The maintainer pushes merged changes to the main repository. keskiviikkona 28. syyskuuta 2011
  • 33. Dictator and Lieutenants Workflow 1. Regular developers work on their topic branch and rebase their work on top of master. The master branch is that of the dictator. 2. Lieutenants merge the developers’ topic branches into their master branch. 3. The dictator merges the lieutenants’ master branches into the dictator’s master branch. 4. The dictator pushes their master to the reference repository so the other developers can rebase on it. keskiviikkona 28. syyskuuta 2011
  • 34. Summary • Git is distributed VCS • Git stores snapshots not changes • Nearly all operations are local and therefore they are very fast • Branch is a snapshot, not files in a separated directory • Git supports multiple remote repositories which enables different workflows • Git is powerful keskiviikkona 28. syyskuuta 2011