SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Git in a Nutshell
         Sort of...

      Mathias Meyer
    www.paperplanes.de

   Ruby User Group Berlin
What the git?

• Git is not the next Subversion
• Git is a content tracker
• Git is almost a versioned file system
• Git is distributed
What the git?


• Git is a huge collection of commands
• Git is f***ing fast
Ancient History
• Developed to replace BitKeeper for the Linux
  kernel development
• Started out as a couple of scripts built by Linus
  Torvalds
• Used by Rails, Merb, Ubuntu, X.org, Wine,
  Rubinius and Linux (whoa!)
• Started out focused on development with a
  central maintainer
Basics

• Every working copy is a full-fledged repository
• Git only tracks content
• Content is identified by a hash
• Though that content has a name
• The same content is only stored once
Basics

• Everything is stored in one .git directory in the
  top level of your working copy
• Git uses an index to find changes in the
  working directory
• The index is a snapshot of a specific tree in the
  repository
Git Objects

• Git knows four types of objects
• Have SHA1 IDs
• Can be addressed with the six first bytes of
  the hash
• Are compressed with gzip
Commits

• Refers to a tree and usually a parent commit
  (usually the commit before the current one)
• Can have two or more parents, then they
  represent a merge
• Or no parent at all
• Stored with a log message
Tree


• A simple structure containing names of blobs
  and other trees
• Represents a snapshot of the source tree
Blob

• Contains data, e.g. file content
• Blobs don’t have names
• Their names are derived from the tree
• Will be found through associations from trees
  and commits
Tag


• Glued to a specific object
• Marks a specific point in the Git timeline with
  a name
HEAD




       branch




       commit




        tree




tree            blob




tree            blob




blob
Git Branches


• master - default development branch
• origin - default upstream branch
• HEAD - current branch
Git Branches
• HEAD~2, master^1, wtf?
• ~N references the Nth generation
  grandparent of a commit
• ^N references the Nth parent of a commit,
  only useful for merges of two or more
  commits
• So....
Git Branches
• HEAD~2 is the second generation grand-
  parent of the last commit on the current
  branch
• master^2 is the second parent of the last
  commit on master
• master~2^2 is the second parent of the
  second generation grand-parent of the last
  commit on the current branch
Git Branches


    Rrright.
Git Branches

• Branches are cheap and easy
• A branch is an ID pointing to a tree and a
  parent commit
• Merging is cheap, fast and almost painless
• Ergo: Branching in Git rocks
How Do I Get Git?

• MacPorts (port install git-core +svn)
• Git Installer for Leopard
• On every Linux distribution (apt-get|rpm
  install git-core)
• On Windows? I think so
How Do I Get Started?

• mkdir project.git
• cd project.git
• git init
• Start hacking
How Do I Get Started?


• Or go to GitHub
• Best GUI for Git evah
Everyday Git


• Some of the commonly used Git commands
• Called the Porcelain
Set up camp


• git config --global user.name “Mathias Meyer”
• git config --global user.email
  “meyer@paperplanes.de”
git clone


• Creates a local working copy of a remote
  project
• git clone git://github.com/mattmatt/
  macistrano.git
git checkout

• Checks out code from a branch
• Will overwrite your local changes
• git checkout -b will create a branch and check
  it out
git branch

• Shows, creates and deletes branches
• git branch
    master
  * show_me_the_money
• git branch new_branch
• git branch -d new_branch
git fetch


• Fetches all objects from a remote repository
  which are not in the local repository
git add


• Schedule changes in one or more files for the
  next commit
git rm



• Removes files
git mv



• Moves files and directories around
git commit
• Isn’t it obvious?
• It will check in your changes
• But only the ones you added
• Use git commit -a to check in all the changes
  without adding them
• git commit <file> will commit the file without
  the need to add it
git status


• Shows staged and unstaged changes
• staged = added
• unstaged = new, conflicts, changed
git push

• Pushes your changes to a remote repository
• git push origin pushes the current branch
• git push origin master pushes the master
  branch
git pull


• Different way to do a merge
• git pull = git fetch + git merge
git log


• Shows the commit history
• Can be verbose if you want it to
git merge

• Merges the changes from a branch into your
  current branch
• git merge rails_2_1
• And that’s that
• In case of conflicts, these need to be resolved
  and then committed
git tag


• Duh!
• Associates a tag with the
git stash
• It’s like a clipboard in your repository
• Need to work on something else but don’t
  want to commit your local changes yet?
• git stash save will save all your changes
• git stash apply will reapply them after you’re
  done
• git stash list shows all the stashes
• git stash show shows the changes of a stash
git show


• Shows the details of a specified, or the last
  commit
git archive

• Creates an export of your repository
• Default is tar
• Convenient, no?
• git archive release_2_1 > release_2_1.tar
git ....

• There’s lots more
• Which you probably won’t need most of the
  time
• You use 20 or so for everyday work
• Some of them only on special occasions
• git-<tab> and start digging
Git-Svn

• The gateway drug for Subversion users
• Warning:You don’t want to use the svn
  command ever again
• Ever!
Git-Svn

• Basically a couple of Perl scripts
• Using the Subversion bindings
• Translates Subversion commits to Git commits
  and vice versa
Show me how!

• mkdir webistrano
• git svn init -s http://labs.peritor.com/svn/
  webistrano
• git svn fetch
• Get a coffee...
Everyday Git-Svn

• git checkout -b make_me_rich
• ...endless hours of coding...
• ...and writing tests...
• git add lib/monetize.rb spec/monetize_spec.rb
• git commit
Everyday Git-Svn -
          Merging
• git commit -a
• git checkout master
• git svn rebase
• git merge make_me_rich
• ...run tests...
• git svn dcommit
• git branch -d make_me_rich
Everyday Git-Svn -
          Merging

• The potentiel downside of using git merge:
• git svn dcommit will check in all the commits
  from the branch in one single svn commit
Everyday Git-Svn -
          Merging

• The alternative
• dcommit from the branch
• rebase the changes on master
Everyday Git-Svn -
         Merging
• git commit -a
• git svn rebase # on branch make_me_rich
• git svn dcommit # on branch make_me_rich
• git checkout master
• git svn rebase
• git branch -d make_me_rich
Some Git Awesomeness

• Find out what commits will be ci’d to svn
 • git svn dcommit -n (rather sparse)
 • git cherry -v trunk (full glory)
• Commit partial changes of a file
 • git add --patch
But I don’t like the CLI

• Use git gui for a “nicer” interface
• Use Gitk to visualize commits and branches
• For both: brace yourself to be blinded
• Much nicer, less powerful: GitNub
• TextMate bundle!
In the end...

• Git will blow your brains out
• In several ways
• It takes a while to get used to it
• But it’s totally worth it
• Even if you’re still using Subversion as a central
  repository
The Bad Stuff

• Poor documentation, be prepared to spend
  some time on Google
• Complex beast, lots of small commands
• No API
Resources
• Git Home (http://www.git.or.cz)
• Git User’s Manual (http://www.kernel.org/pub/
  software/scm/git/docs/user-manual.html)
• Git PeepCode (http://peepcode.com/products/
  git)
• Must-read: Git Internals (http://peepcode.com/
  products/git-internals-pdf)
• GitCasts (http://www.gitcasts.com/)

Contenu connexe

Tendances

Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails UndergroundAriejan de Vroom
 
Git As A Subversion Replacement
Git As A Subversion ReplacementGit As A Subversion Replacement
Git As A Subversion ReplacementJosh Nichols
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductortimyates
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
 
Rh developers fat jar smackdown
Rh developers   fat jar smackdownRh developers   fat jar smackdown
Rh developers fat jar smackdownRed Hat Developers
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advancedYodalee
 
From svn to git
From svn to gitFrom svn to git
From svn to gitNehal Shah
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015mwrather
 

Tendances (20)

Git and Github
Git and GithubGit and Github
Git and Github
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Hg for bioinformatics, second part
Hg for bioinformatics, second partHg for bioinformatics, second part
Hg for bioinformatics, second part
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Git As A Subversion Replacement
Git As A Subversion ReplacementGit As A Subversion Replacement
Git As A Subversion Replacement
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
 
Hg version control bioinformaticians
Hg version control bioinformaticiansHg version control bioinformaticians
Hg version control bioinformaticians
 
Inside GitHub with Chris Wanstrath
Inside GitHub with Chris WanstrathInside GitHub with Chris Wanstrath
Inside GitHub with Chris Wanstrath
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Rh developers fat jar smackdown
Rh developers   fat jar smackdownRh developers   fat jar smackdown
Rh developers fat jar smackdown
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
From svn to git
From svn to gitFrom svn to git
From svn to git
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
 
Basic git
Basic gitBasic git
Basic git
 

Similaire à Smalltalk on Git

Similaire à Smalltalk on Git (20)

Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCS
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCS
 
Git presentation
Git presentationGit presentation
Git presentation
 
Git
GitGit
Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git & gitflow
Git & gitflowGit & gitflow
Git & gitflow
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
3 Git
3 Git3 Git
3 Git
 
Git basics
Git basicsGit basics
Git basics
 
M.Mozūras - git
M.Mozūras - gitM.Mozūras - git
M.Mozūras - git
 
版本控制Git
版本控制Git版本控制Git
版本控制Git
 
Git: Why And How to
Git: Why And How toGit: Why And How to
Git: Why And How to
 

Plus de mattmatt

Cloud Conf - Datenbanken in der Cloud
Cloud Conf - Datenbanken in der CloudCloud Conf - Datenbanken in der Cloud
Cloud Conf - Datenbanken in der Cloudmattmatt
 
Redis - N✮SQL Berlin
Redis - N✮SQL BerlinRedis - N✮SQL Berlin
Redis - N✮SQL Berlinmattmatt
 
Mein Freund Der Legacy Code
Mein Freund Der Legacy CodeMein Freund Der Legacy Code
Mein Freund Der Legacy Codemattmatt
 
RabbitMQ And Nanite
RabbitMQ And NaniteRabbitMQ And Nanite
RabbitMQ And Nanitemattmatt
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Rubymattmatt
 
Upstream Goes To Maine
Upstream Goes To MaineUpstream Goes To Maine
Upstream Goes To Mainemattmatt
 

Plus de mattmatt (6)

Cloud Conf - Datenbanken in der Cloud
Cloud Conf - Datenbanken in der CloudCloud Conf - Datenbanken in der Cloud
Cloud Conf - Datenbanken in der Cloud
 
Redis - N✮SQL Berlin
Redis - N✮SQL BerlinRedis - N✮SQL Berlin
Redis - N✮SQL Berlin
 
Mein Freund Der Legacy Code
Mein Freund Der Legacy CodeMein Freund Der Legacy Code
Mein Freund Der Legacy Code
 
RabbitMQ And Nanite
RabbitMQ And NaniteRabbitMQ And Nanite
RabbitMQ And Nanite
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Ruby
 
Upstream Goes To Maine
Upstream Goes To MaineUpstream Goes To Maine
Upstream Goes To Maine
 

Dernier

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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 TerraformAndrey Devyatkin
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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 CVKhem
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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 FresherRemote DBA Services
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 

Smalltalk on Git

  • 1. Git in a Nutshell Sort of... Mathias Meyer www.paperplanes.de Ruby User Group Berlin
  • 2. What the git? • Git is not the next Subversion • Git is a content tracker • Git is almost a versioned file system • Git is distributed
  • 3. What the git? • Git is a huge collection of commands • Git is f***ing fast
  • 4. Ancient History • Developed to replace BitKeeper for the Linux kernel development • Started out as a couple of scripts built by Linus Torvalds • Used by Rails, Merb, Ubuntu, X.org, Wine, Rubinius and Linux (whoa!) • Started out focused on development with a central maintainer
  • 5. Basics • Every working copy is a full-fledged repository • Git only tracks content • Content is identified by a hash • Though that content has a name • The same content is only stored once
  • 6. Basics • Everything is stored in one .git directory in the top level of your working copy • Git uses an index to find changes in the working directory • The index is a snapshot of a specific tree in the repository
  • 7. Git Objects • Git knows four types of objects • Have SHA1 IDs • Can be addressed with the six first bytes of the hash • Are compressed with gzip
  • 8. Commits • Refers to a tree and usually a parent commit (usually the commit before the current one) • Can have two or more parents, then they represent a merge • Or no parent at all • Stored with a log message
  • 9. Tree • A simple structure containing names of blobs and other trees • Represents a snapshot of the source tree
  • 10. Blob • Contains data, e.g. file content • Blobs don’t have names • Their names are derived from the tree • Will be found through associations from trees and commits
  • 11. Tag • Glued to a specific object • Marks a specific point in the Git timeline with a name
  • 12. HEAD branch commit tree tree blob tree blob blob
  • 13. Git Branches • master - default development branch • origin - default upstream branch • HEAD - current branch
  • 14. Git Branches • HEAD~2, master^1, wtf? • ~N references the Nth generation grandparent of a commit • ^N references the Nth parent of a commit, only useful for merges of two or more commits • So....
  • 15. Git Branches • HEAD~2 is the second generation grand- parent of the last commit on the current branch • master^2 is the second parent of the last commit on master • master~2^2 is the second parent of the second generation grand-parent of the last commit on the current branch
  • 16. Git Branches Rrright.
  • 17. Git Branches • Branches are cheap and easy • A branch is an ID pointing to a tree and a parent commit • Merging is cheap, fast and almost painless • Ergo: Branching in Git rocks
  • 18. How Do I Get Git? • MacPorts (port install git-core +svn) • Git Installer for Leopard • On every Linux distribution (apt-get|rpm install git-core) • On Windows? I think so
  • 19. How Do I Get Started? • mkdir project.git • cd project.git • git init • Start hacking
  • 20. How Do I Get Started? • Or go to GitHub • Best GUI for Git evah
  • 21. Everyday Git • Some of the commonly used Git commands • Called the Porcelain
  • 22. Set up camp • git config --global user.name “Mathias Meyer” • git config --global user.email “meyer@paperplanes.de”
  • 23. git clone • Creates a local working copy of a remote project • git clone git://github.com/mattmatt/ macistrano.git
  • 24. git checkout • Checks out code from a branch • Will overwrite your local changes • git checkout -b will create a branch and check it out
  • 25. git branch • Shows, creates and deletes branches • git branch master * show_me_the_money • git branch new_branch • git branch -d new_branch
  • 26. git fetch • Fetches all objects from a remote repository which are not in the local repository
  • 27. git add • Schedule changes in one or more files for the next commit
  • 29. git mv • Moves files and directories around
  • 30. git commit • Isn’t it obvious? • It will check in your changes • But only the ones you added • Use git commit -a to check in all the changes without adding them • git commit <file> will commit the file without the need to add it
  • 31. git status • Shows staged and unstaged changes • staged = added • unstaged = new, conflicts, changed
  • 32. git push • Pushes your changes to a remote repository • git push origin pushes the current branch • git push origin master pushes the master branch
  • 33. git pull • Different way to do a merge • git pull = git fetch + git merge
  • 34. git log • Shows the commit history • Can be verbose if you want it to
  • 35. git merge • Merges the changes from a branch into your current branch • git merge rails_2_1 • And that’s that • In case of conflicts, these need to be resolved and then committed
  • 36. git tag • Duh! • Associates a tag with the
  • 37. git stash • It’s like a clipboard in your repository • Need to work on something else but don’t want to commit your local changes yet? • git stash save will save all your changes • git stash apply will reapply them after you’re done • git stash list shows all the stashes • git stash show shows the changes of a stash
  • 38. git show • Shows the details of a specified, or the last commit
  • 39. git archive • Creates an export of your repository • Default is tar • Convenient, no? • git archive release_2_1 > release_2_1.tar
  • 40. git .... • There’s lots more • Which you probably won’t need most of the time • You use 20 or so for everyday work • Some of them only on special occasions • git-<tab> and start digging
  • 41. Git-Svn • The gateway drug for Subversion users • Warning:You don’t want to use the svn command ever again • Ever!
  • 42. Git-Svn • Basically a couple of Perl scripts • Using the Subversion bindings • Translates Subversion commits to Git commits and vice versa
  • 43. Show me how! • mkdir webistrano • git svn init -s http://labs.peritor.com/svn/ webistrano • git svn fetch • Get a coffee...
  • 44. Everyday Git-Svn • git checkout -b make_me_rich • ...endless hours of coding... • ...and writing tests... • git add lib/monetize.rb spec/monetize_spec.rb • git commit
  • 45. Everyday Git-Svn - Merging • git commit -a • git checkout master • git svn rebase • git merge make_me_rich • ...run tests... • git svn dcommit • git branch -d make_me_rich
  • 46. Everyday Git-Svn - Merging • The potentiel downside of using git merge: • git svn dcommit will check in all the commits from the branch in one single svn commit
  • 47. Everyday Git-Svn - Merging • The alternative • dcommit from the branch • rebase the changes on master
  • 48. Everyday Git-Svn - Merging • git commit -a • git svn rebase # on branch make_me_rich • git svn dcommit # on branch make_me_rich • git checkout master • git svn rebase • git branch -d make_me_rich
  • 49. Some Git Awesomeness • Find out what commits will be ci’d to svn • git svn dcommit -n (rather sparse) • git cherry -v trunk (full glory) • Commit partial changes of a file • git add --patch
  • 50. But I don’t like the CLI • Use git gui for a “nicer” interface • Use Gitk to visualize commits and branches • For both: brace yourself to be blinded • Much nicer, less powerful: GitNub • TextMate bundle!
  • 51. In the end... • Git will blow your brains out • In several ways • It takes a while to get used to it • But it’s totally worth it • Even if you’re still using Subversion as a central repository
  • 52. The Bad Stuff • Poor documentation, be prepared to spend some time on Google • Complex beast, lots of small commands • No API
  • 53. Resources • Git Home (http://www.git.or.cz) • Git User’s Manual (http://www.kernel.org/pub/ software/scm/git/docs/user-manual.html) • Git PeepCode (http://peepcode.com/products/ git) • Must-read: Git Internals (http://peepcode.com/ products/git-internals-pdf) • GitCasts (http://www.gitcasts.com/)