SlideShare a Scribd company logo
1 of 24
Download to read offline
Git: a brief
                                  introduction
                     Randal L. Schwartz, merlyn@stonehenge.com
                             Version 5.0.2 on 28 Jul 2012

                        This document is copyright 2011, 2012 by Randal L. Schwartz, Stonehenge Consulting Services, Inc.
                  This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
                                                http://creativecommons.org/licenses/by-nc-sa/3.0/




Saturday, August 4, 12
Overview

                     •   Key concepts of git
                     •   Using git by yourself
                     •   Using git with others




Saturday, August 4, 12
Key concepts
                     •   Manages trees, not files
                     •   Stores entire history for a commit
                     •   Serverless (mostly)
                     •   Source-code manager
                       •   No meta-data
                       •   Handles binaries badly
                     •   Optimized for branch/merge
                       •   If not branching or merging, bad fit



Saturday, August 4, 12
The moving parts
                     •   Stored in “.git”:
                         • Object repository
                           • files (“blob”), directories, commits
                         • Operational files (config, etc.)
                     •   Working directory
                     •   Low-level CLI (“plumbing”)
                     •   High-level CLI (“porcelain”)
                     •   Various GUIs
                     •   Various web UIs



Saturday, August 4, 12
Commits
                     •   Unit of work
                     •   Usually has a parent
                         • Two or more on a merge
                         • Zero on a “root” commit
                     •   Metadata (committer, message, timestamps)
                     •   Tree of files at time of commit




Saturday, August 4, 12
Trees
                     • SHA1 of each file in a directory
                     • SHA1 of each directory
                       • ... recursively
                     • These are kept efficiently in the object store
                     • Identical files map to same SHA1, stored once
                       • And so do identical trees!
                     • No penalty to “move” a subdirectory or file

Saturday, August 4, 12
Making commits
                     • Changes made to work dir
                     • Added to index with “git add”
                     • Committed with “git commit”
                     • Commit updates HEAD
                       • Prior value of HEAD is the parent
                     • HEAD almost always points at a branch name
                       • Thus, branch name is also moved forward
                     • Series of commits loosely also called “branch”
                     • Commit also gets a SHA1

Saturday, August 4, 12
The SHA1 is king
                     •   SHA1 of commit defines:
                         • Metadata of commit
                         • Tree of files
                         • Parentage
                     •   Parentage defines previous commits
                     •   Thus, SHA1 uniquely defines complete history
                     •   Useful when working with others




Saturday, August 4, 12
Naming commits
                     •   SHA1 (can often be abbreviated)
                     •   HEAD, branch-name, tag
                     •   Optionally followed by @{historical}
                     •   “historical” can be:
                         • yesterday, 2011-11-22, etc (date ref)
                         • 1, 2, 3, etc (prior version of this ref)
                         • “upstream” (upstream version of local)
                     •   Optionally followed by ~n for “n’th ancestor”



Saturday, August 4, 12
Branches
                     • Initial branch is “master” (name not special)
                     • Fork the current branch:
                       git checkout -b topic1
                     • topic1 is set to same SHA1 as previous branch
                     • HEAD now points at topic1
                       • New commits now apply to topic1
                     • Switch back with “git checkout master”

Saturday, August 4, 12
Multiple branches
                     •   Start a second topic based on original master:
                         git checkout -b topic2 master
                     •   Work, work, commit, commit
                     •   Switch back and forth at will:
                         git checkout topic1
                     •   Topics record independent deltas to master
                         •  A B C (master) D E F (topic1)
                         •  A B C (master) G H I (topic2)



Saturday, August 4, 12
Combining the work
                     •   Merge the work back in to master:
                         git checkout master
                         git merge topic1
                         git branch -d topic1
                     •   This was a fast-forward merge:
                         A B C D E F (new “master”)
                         A B C G H I (topic2)




Saturday, August 4, 12
Really merging
                     •   Now to bring topic2 back into the mix:
                         git checkout master # already there
                         git merge topic2
                     •   Three-way merge between master, topic2,
                         relative to common ancestor (“C”)
                     •   Might cause conflicts
                     •   New commit will have both F and I as parents
                     •   History is no longer linear
                         •  DEF and GHI will appear as parallel lines



Saturday, August 4, 12
Linear history
                     •   We can “rebase” commits:
                         A B C D E F (master)
                         A B C G H I (topic2)
                         git checkout topic2; git rebase master
                     •   Git replays new commits on top of ancestor:
                         A B C D E F (master) G’ H’ I’ (topic2)
                     •   Might cause conflicts at each replay
                     •   Need to clean up when done:
                         git checkout master; git merge topic2
                         git branch -d topic2


Saturday, August 4, 12
Rebase vs merge
                     • Both can have conflicts
                     • Merge makes a bushy tree
                       • Hard to peel out “linear” history
                     • Rebase makes a linear tree
                       • But gets rid of commits
                     • Rebase is nicer, but you must take care
                       • Shared commits should not be rebased

Saturday, August 4, 12
Using git yourself
                     •   Create the repo at your top-level dir:
                         git init
                         git add -A . # or git add *
                         git commit # invokes a text editor
                     •   You now have a single “.git” dir
                     •   The current working dir snapshotted as root




Saturday, August 4, 12
Work a bit
                     •   Edit some files
                     •   Check the status: git status
                     •   Add all the changes and commit them:
                         git add -A .
                         git commit
                     •   Shortcut if you haven’t added new files:
                         git commit -a
                     •   You’re making commits on the master branch



Saturday, August 4, 12
What’s changed?
                     •   git diff
                       •    Diff between index and working tree
                       •    These are things you should “git add”
                       •    “git commit -a” will also make this list empty
                     •   git diff HEAD
                       •    Difference between HEAD and working tree
                       •    “git commit -a” will make this empty
                     •   git diff --cached
                       •    between HEAD and index
                       •    “git commit” (without -a) makes this empty


Saturday, August 4, 12
Useful commands
                     •   git archive: export a tree as a tar/zip
                     •   git bisect: find the offensive commit
                     •   git cherry-pick: selective merging
                     •   git mv: rename a file/dir
                     •   git rm: ditto for delete
                     •   git revert: add commit to undo previous commit
                     •   git blame: who wrote this?




Saturday, August 4, 12
Read the history
                     • git log
                       • print the changes
                     • git log -p
                       • print the changes, including a diff between
                          revisions
                     • git log --stat
                       • Summarize the changes with a diffstat
                     • git log -- file1 file2 dir3
                       • Show changes only for listed files or subdirs

Saturday, August 4, 12
Using git with others
                     •   Commits can be transmitted by many protocols
                         •  On disk
                         •  HTTP[S]
                         •  git protocol over TCP
                         •  git protocol over SSH
                     •   git over SSH is preferred




Saturday, August 4, 12
Getting commits
                     •   Most likely: git clone over SSH:
                         git clone user@host:/some/path/to/repo.git
                     •   Makes local repo.git dir
                     •   Checks out remote repo’s “HEAD” as master
                     •   Adds remote repo as “origin”
                         •  Nothing special about that name




Saturday, August 4, 12
Working with upstream
                     •   Work on local master:
                         edit edit; git commit -a
                     •   Refresh from upstream
                         •  By merge: git pull origin master
                         •  By rebase: git pull --rebase origin master
                     •   Push to upstream:
                         git push origin master
                     •   Check what’s different before pull:
                         git fetch origin; git diff master origin/master



Saturday, August 4, 12
For further info
                     •   See “Git (software)” in Wikipedia
                     •   And the git homepage http://git-scm.com/
                     •   Git wiki at https://git.wiki.kernel.org/
                     •   Wonderful Pro Git book: http://progit.org/book/
                     •   Get on the mailing list
                         • Helpful people there
                         • You can submit bugs, patches, ideas
                     •   And the #git IRC channel (on Freenode)
                     •   Now “git” to it!



Saturday, August 4, 12

More Related Content

What's hot

An introduction to git
An introduction to gitAn introduction to git
An introduction to gitolberger
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started PresentationNap Ramirez
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSMAU
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time rebootKentaro Goto
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Mandi Walls
 
Introduction to github using Egit
Introduction to github using EgitIntroduction to github using Egit
Introduction to github using Egitmatz_twt
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucketazwildcat
 
VCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopVCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopAnis Ahmad
 
Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Gibson Fahnestock
 

What's hot (20)

An introduction to git
An introduction to gitAn introduction to git
An introduction to git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started Presentation
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro Locati
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
 
Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Talk to git
Talk to gitTalk to git
Talk to git
 
Introduction to github using Egit
Introduction to github using EgitIntroduction to github using Egit
Introduction to github using Egit
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
VCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopVCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT Workshop
 
Git 101
Git 101Git 101
Git 101
 
Domino testing presentation
Domino testing presentationDomino testing presentation
Domino testing presentation
 
Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Node.js what's next (Index 2018)
Node.js what's next (Index 2018)
 
Rupher = Ruby + Gopther
Rupher = Ruby + GoptherRupher = Ruby + Gopther
Rupher = Ruby + Gopther
 
Rupher
RupherRupher
Rupher
 

Similar to Intro to git (one hour version)

Similar to Intro to git (one hour version) (19)

Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
Git session-2012-2013
Git session-2012-2013Git session-2012-2013
Git session-2012-2013
 
Git
GitGit
Git
 
Demystifying git
Demystifying git Demystifying git
Demystifying git
 
6 git
6 git6 git
6 git
 
Do you really understand Git?
Do you really understand Git?Do you really understand Git?
Do you really understand Git?
 
Git censored.key
Git censored.keyGit censored.key
Git censored.key
 
Git Real
Git RealGit Real
Git Real
 
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
 
12-BigDataMapReduce.pptx
12-BigDataMapReduce.pptx12-BigDataMapReduce.pptx
12-BigDataMapReduce.pptx
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop
 
Mongodb my
Mongodb myMongodb my
Mongodb my
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
January 2022: Central Iowa Linux Users Group: Git
January 2022: Central Iowa Linux Users Group: GitJanuary 2022: Central Iowa Linux Users Group: Git
January 2022: Central Iowa Linux Users Group: Git
 
What git is
What git isWhat git is
What git is
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Iwmn architecture
Iwmn architectureIwmn architecture
Iwmn architecture
 

More from Randal Schwartz

Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Randal Schwartz
 
A brief introduction to dart
A brief introduction to dartA brief introduction to dart
A brief introduction to dartRandal Schwartz
 

More from Randal Schwartz (7)

Why Flutter.pdf
Why Flutter.pdfWhy Flutter.pdf
Why Flutter.pdf
 
Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)
 
Perl best practices v4
Perl best practices v4Perl best practices v4
Perl best practices v4
 
A brief introduction to dart
A brief introduction to dartA brief introduction to dart
A brief introduction to dart
 
My half life with perl
My half life with perlMy half life with perl
My half life with perl
 
Testing scripts
Testing scriptsTesting scripts
Testing scripts
 
Forget The ORM!
Forget The ORM!Forget The ORM!
Forget The ORM!
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Intro to git (one hour version)

  • 1. Git: a brief introduction Randal L. Schwartz, merlyn@stonehenge.com Version 5.0.2 on 28 Jul 2012 This document is copyright 2011, 2012 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License http://creativecommons.org/licenses/by-nc-sa/3.0/ Saturday, August 4, 12
  • 2. Overview • Key concepts of git • Using git by yourself • Using git with others Saturday, August 4, 12
  • 3. Key concepts • Manages trees, not files • Stores entire history for a commit • Serverless (mostly) • Source-code manager • No meta-data • Handles binaries badly • Optimized for branch/merge • If not branching or merging, bad fit Saturday, August 4, 12
  • 4. The moving parts • Stored in “.git”: • Object repository • files (“blob”), directories, commits • Operational files (config, etc.) • Working directory • Low-level CLI (“plumbing”) • High-level CLI (“porcelain”) • Various GUIs • Various web UIs Saturday, August 4, 12
  • 5. Commits • Unit of work • Usually has a parent • Two or more on a merge • Zero on a “root” commit • Metadata (committer, message, timestamps) • Tree of files at time of commit Saturday, August 4, 12
  • 6. Trees • SHA1 of each file in a directory • SHA1 of each directory • ... recursively • These are kept efficiently in the object store • Identical files map to same SHA1, stored once • And so do identical trees! • No penalty to “move” a subdirectory or file Saturday, August 4, 12
  • 7. Making commits • Changes made to work dir • Added to index with “git add” • Committed with “git commit” • Commit updates HEAD • Prior value of HEAD is the parent • HEAD almost always points at a branch name • Thus, branch name is also moved forward • Series of commits loosely also called “branch” • Commit also gets a SHA1 Saturday, August 4, 12
  • 8. The SHA1 is king • SHA1 of commit defines: • Metadata of commit • Tree of files • Parentage • Parentage defines previous commits • Thus, SHA1 uniquely defines complete history • Useful when working with others Saturday, August 4, 12
  • 9. Naming commits • SHA1 (can often be abbreviated) • HEAD, branch-name, tag • Optionally followed by @{historical} • “historical” can be: • yesterday, 2011-11-22, etc (date ref) • 1, 2, 3, etc (prior version of this ref) • “upstream” (upstream version of local) • Optionally followed by ~n for “n’th ancestor” Saturday, August 4, 12
  • 10. Branches • Initial branch is “master” (name not special) • Fork the current branch: git checkout -b topic1 • topic1 is set to same SHA1 as previous branch • HEAD now points at topic1 • New commits now apply to topic1 • Switch back with “git checkout master” Saturday, August 4, 12
  • 11. Multiple branches • Start a second topic based on original master: git checkout -b topic2 master • Work, work, commit, commit • Switch back and forth at will: git checkout topic1 • Topics record independent deltas to master • A B C (master) D E F (topic1) • A B C (master) G H I (topic2) Saturday, August 4, 12
  • 12. Combining the work • Merge the work back in to master: git checkout master git merge topic1 git branch -d topic1 • This was a fast-forward merge: A B C D E F (new “master”) A B C G H I (topic2) Saturday, August 4, 12
  • 13. Really merging • Now to bring topic2 back into the mix: git checkout master # already there git merge topic2 • Three-way merge between master, topic2, relative to common ancestor (“C”) • Might cause conflicts • New commit will have both F and I as parents • History is no longer linear • DEF and GHI will appear as parallel lines Saturday, August 4, 12
  • 14. Linear history • We can “rebase” commits: A B C D E F (master) A B C G H I (topic2) git checkout topic2; git rebase master • Git replays new commits on top of ancestor: A B C D E F (master) G’ H’ I’ (topic2) • Might cause conflicts at each replay • Need to clean up when done: git checkout master; git merge topic2 git branch -d topic2 Saturday, August 4, 12
  • 15. Rebase vs merge • Both can have conflicts • Merge makes a bushy tree • Hard to peel out “linear” history • Rebase makes a linear tree • But gets rid of commits • Rebase is nicer, but you must take care • Shared commits should not be rebased Saturday, August 4, 12
  • 16. Using git yourself • Create the repo at your top-level dir: git init git add -A . # or git add * git commit # invokes a text editor • You now have a single “.git” dir • The current working dir snapshotted as root Saturday, August 4, 12
  • 17. Work a bit • Edit some files • Check the status: git status • Add all the changes and commit them: git add -A . git commit • Shortcut if you haven’t added new files: git commit -a • You’re making commits on the master branch Saturday, August 4, 12
  • 18. What’s changed? • git diff • Diff between index and working tree • These are things you should “git add” • “git commit -a” will also make this list empty • git diff HEAD • Difference between HEAD and working tree • “git commit -a” will make this empty • git diff --cached • between HEAD and index • “git commit” (without -a) makes this empty Saturday, August 4, 12
  • 19. Useful commands • git archive: export a tree as a tar/zip • git bisect: find the offensive commit • git cherry-pick: selective merging • git mv: rename a file/dir • git rm: ditto for delete • git revert: add commit to undo previous commit • git blame: who wrote this? Saturday, August 4, 12
  • 20. Read the history • git log • print the changes • git log -p • print the changes, including a diff between revisions • git log --stat • Summarize the changes with a diffstat • git log -- file1 file2 dir3 • Show changes only for listed files or subdirs Saturday, August 4, 12
  • 21. Using git with others • Commits can be transmitted by many protocols • On disk • HTTP[S] • git protocol over TCP • git protocol over SSH • git over SSH is preferred Saturday, August 4, 12
  • 22. Getting commits • Most likely: git clone over SSH: git clone user@host:/some/path/to/repo.git • Makes local repo.git dir • Checks out remote repo’s “HEAD” as master • Adds remote repo as “origin” • Nothing special about that name Saturday, August 4, 12
  • 23. Working with upstream • Work on local master: edit edit; git commit -a • Refresh from upstream • By merge: git pull origin master • By rebase: git pull --rebase origin master • Push to upstream: git push origin master • Check what’s different before pull: git fetch origin; git diff master origin/master Saturday, August 4, 12
  • 24. For further info • See “Git (software)” in Wikipedia • And the git homepage http://git-scm.com/ • Git wiki at https://git.wiki.kernel.org/ • Wonderful Pro Git book: http://progit.org/book/ • Get on the mailing list • Helpful people there • You can submit bugs, patches, ideas • And the #git IRC channel (on Freenode) • Now “git” to it! Saturday, August 4, 12