SlideShare a Scribd company logo
1 of 42
Download to read offline
of every day
Notions and more
Alan Descoins
Tryolabs, 2014
Goals
● Better understand what we do every day
● Ask less questions (understand the man)
● Improve some practices
● Make fewer mistakes
● Do something super specific ;)
● 2005, Linux kernel
● Efficiency, simple design
● Non-linear development
(thousands of parallel
branches)
● Completely distributed
Origins and philosophy
Distributed
● Nearly all operations
are local
● All the machines have
ALL the information
● Contrast with SVN,
CVS, etc.
Some theory
● git init initializes a repository
● Creates only one .git directory in the root (doesn’t
pollute)
● Mini filesystem
● Snapshots, not differences!
Git and the content
● Tracking of content, NOT files
● Vocabulary: tracked / untracked
● Git objects
○ Blob (content)
○ Tree (structure)
○ Commit (points to a tree, + data)
○ Tag (points to a commit, + data)
SHA-1
● One file per “content”
● SHA-1 of the content (zlib) + a
header
● Initially, loose object
● Then packfile (efficiency,
heuristics…)
● Example: find .git/objects -type f
Blob
Tree
● Like a directory structure
● Pointers to blobs or other trees
● Represents a complete
snapshot of the state
● Example: git ls-tree <sha-1>
Commit
● Information about the trees
● Who, when, why saved the tree
● Points to the top level tree of the project
● Tree hierarchy
● Also SHA-1, different hash than the tree it
points to
Commit (2)
Tags
● Pointer to a commit
● Additional information, signature
● So we don’t have to remember
the SHA-1...
The Holy Trinity
A content may be in three states:
● Committed
● Modified
● Staged
The Holy Trinity (2)
Three parts of a project:
● Working directory
● Staging area (or index)
● .git (repository)
Basic commands
● git add - adds to the index (staging)
● git commit - saves the index together with author,
message, date, etc.
● git status - shows the file with differences between the
working dir, staging, and the untracked
● git diff - what changed but is not staged
● git diff --cached - what is going in the next commit
● git log
Avoiding the staging
● Sometimes, it may be easier to avoid the
staging area
● git commit -a | git commit <archivo>
● Automatically add to the staging, then
commit
Branches
● Simply a pointer to a commit
● As fast as it is to write 41 characters to a file
(SHA-1 + n)
● By default master
● Special pointer HEAD (current branch)
● Example: cat .git/HEAD
Branches (2)
● git checkout to
switch
branches
References
● The HEAD pointer is a special case
● Tags too: “an unmovable branch”
(lightweight tags)
Example: find .git/refs
Remotes
● No central server
● Can add several remotes, external copies of
the repo (URL)
● The famous origin :)
Remote branches
● Save the state of branches in remote repositories
● They are local, but cannot be moved, only when you do
network operations (eg. git fetch).
● The form is <remote>/<branch>
Example: cat .git/refs/remotes/origin/master
Fetch, push
● git fetch - sync and update remote branches (moves
pointers)
● Eg. git fetch <remote>
● git pull - equivalent to git fetch and the git merge,
merges the local branch with the changes in the remote
● git push - update the remote branch with the local data
● Eg. git push <remote> <branch>
Tracking branches
● Local branches can “track” remote ones
● Two possibilities:
○ git checkout --track <remote>/<branch>
○ git push --set-upstream <remote> <branch>
● Now, when pushing you don’t have to type
the name of the remote and the branch :)
Merges
● Fast-forward: git is smart
and only needs to move a
pointer
● Integrate changes of one branch into
another
Merges (2)
● Three way merge: commit not direct
ancestor of what I am merging in (non linear)
● Git determines the best common ancestor
● A merge commit is created, special because
it has more than one parent
● Conflicts...
Three way merge
Rebasing
● Another way to introduce changes of one
branch into another
● Rewind & replay, rewrites the commits
● From a common ancestor
● History is always linear, even though it was
work originally done in parallel
Rebasing (2)
● git rebase <new-base>
moves the commits from
the current branch to the
new base
● git rebase -i <new-base>
lets us select actions for
every commit
● git pull --rebase
● Never do rebase of a branch that is already pushed,
or you pulled from somebody else
○ Duplicate commits if someone does merge
○ Arguable: if the remote branch is yours and used as backup
○ Use git push --force, if you are certain nobody else works in the
branch
● If you rebase to get changes by other developers
locally, do it as often as possible.
Golden rules
Rebase vs Merge
Why rebase?
● Clean, linear history
● Open-source collaboration, many demand it
● Easier for code review
Why merge?
● Easier to solve conflicts (only once)
● Less risk
git reset
● Often used
● Used wrong, can cause loss of data
(workdir unsafe)
● Three most used options:
○ --soft
○ --mixed
○ --hard
git reset...
● move the branch HEAD points to so it points to target
commit (stop if --soft)
● then make the staging look like that (stop if --mixed,
default option)
● then make the working dir look like that (if --hard, it is
workdir usafe!)
Examples of git reset
● With HEAD in dev branch, do git reset master
○ now dev y master point to the same commit
● With HEAD in branch master, do git reset --hard
origin/master
○ now my local master branch is identical to the
remote (discard local changes)
● git reset --soft HEAD~
○ Undo the last commit without losing changes
Unstaging files
● When doing git reset <file> we don’t specify
a branch or commit SHA
● Equivalent to git reset --mixed HEAD <file>
● Moves a particular file out of staging,
opposite of git add :)
git checkout
● git checkout <branch> is superficially similar
to git reset --hard <branch>
● Two differences:
○ Workdir safe! :D Checks to avoid data loss.
○ reset moves the branch that HEAD points to,
checkout moves the HEAD pointer itself.
git checkout of a file
● git checkout <branch> <file>
○ As with reset, now it doesn’t make sense for it to
move HEAD. Replaces only <file> in the workdir
(workdir usafe!).
○ Would be the same as git reset --hard <branch>
<file>
○ But that command does not exist :)
Common situations (1)
● “I need to pull but there are changes I am
working on, and I don’t want to commit yet”
○ git stash
○ It’s a stack
○ Apply with git stash pop.
Common situations (2)
● “There is a bug in a branch, I need to know
what commit introduced it”
○ git bisect
○ Binary search, driven by git. Very easy!
○ git bisect start
git bisect bad <commit>
git bisect good <commit>
● Test on every step (git makes a checkout)
Common situations (3)
● “I made one (or several) commits in the
wrong branch, haven’t yet pushed though!”
○ If the correct branch does not yet exist
■ git checkout -b <correct branch>
■ git reset over the old branch
○ If the branch already existed
■ git cherry-pick (or git rebase --onto)
■ git reset over the old branch
Common situations (4)
● “I have many changes in a file and only want
to commit some of them”
○ git add -p or git commit -p
○ git will ask for every part, whether to add it or not
Common situations (5)
● “I need to change some commits”
● “I need to delete some commits”
● “I need to change the order of some
commits”
○ git rebase -i (--interactive)
○ Easy to use
○ Rewrites history, asking us what to do for each
commit
Common situations (6)
● “I am doing a merge with many conflicts and
I want to stop it and get back to where I was
before”
○ git merge --abort
(Images from git-scm and others ;) )
Didn’t learn git

More Related Content

What's hot

What's hot (19)

11 git version control
11 git version control11 git version control
11 git version control
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
Git: from Novice to Expert
Git: from Novice to ExpertGit: from Novice to Expert
Git: from Novice to Expert
 
Git 101
Git 101Git 101
Git 101
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git basics
Git basicsGit basics
Git basics
 
Git (Internals)
Git (Internals)Git (Internals)
Git (Internals)
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Git commands
Git commandsGit commands
Git commands
 
Git basics
Git basicsGit basics
Git basics
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
 
Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
 
Getting Started on distributed version control with git
Getting Started on distributed version control with gitGetting Started on distributed version control with git
Getting Started on distributed version control with git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 

Viewers also liked

Schedule of creation process - Taylor sabga
Schedule of creation process - Taylor sabgaSchedule of creation process - Taylor sabga
Schedule of creation process - Taylor sabgaTaylor Sabga
 
Học tiêng anh
Học tiêng anhHọc tiêng anh
Học tiêng anhLethang
 
jump! rubberneck spirit of the 70s
jump! rubberneck   spirit of the 70sjump! rubberneck   spirit of the 70s
jump! rubberneck spirit of the 70sjump! innovation
 
AS Media Schedule - Taylor Sabga
AS Media Schedule - Taylor SabgaAS Media Schedule - Taylor Sabga
AS Media Schedule - Taylor SabgaTaylor Sabga
 
3 states of matter
3 states of matter3 states of matter
3 states of matterBrian Chan
 
Schedule REAL - taylor sabga
Schedule REAL -  taylor sabgaSchedule REAL -  taylor sabga
Schedule REAL - taylor sabgaTaylor Sabga
 
Biznesa vadības sistēmas
Biznesa vadības sistēmas Biznesa vadības sistēmas
Biznesa vadības sistēmas Ozols Grupa, Ltd
 
Digitize document management solution
Digitize document management solutionDigitize document management solution
Digitize document management solutionAnshika MIshra
 
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumos
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumosAtvērtā pirmkoda programmatūra mazos un vidējos uzņēmumos
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumosOzols Grupa, Ltd
 
This is what i do!!!!!
This is what i do!!!!!This is what i do!!!!!
This is what i do!!!!!Staci Bennett
 
Pētījumi par IT lietošanu uzņēmumos
Pētījumi par IT lietošanu uzņēmumosPētījumi par IT lietošanu uzņēmumos
Pētījumi par IT lietošanu uzņēmumosOzols Grupa, Ltd
 
Digitize document management solution
Digitize document management solutionDigitize document management solution
Digitize document management solutionAnshika MIshra
 
Splunk for AWS (Bagels and Bytes)
Splunk for AWS (Bagels and Bytes)Splunk for AWS (Bagels and Bytes)
Splunk for AWS (Bagels and Bytes)Dominique Dessy
 

Viewers also liked (20)

Schedule of creation process - Taylor sabga
Schedule of creation process - Taylor sabgaSchedule of creation process - Taylor sabga
Schedule of creation process - Taylor sabga
 
Học tiêng anh
Học tiêng anhHọc tiêng anh
Học tiêng anh
 
jump! rubberneck spirit of the 70s
jump! rubberneck   spirit of the 70sjump! rubberneck   spirit of the 70s
jump! rubberneck spirit of the 70s
 
AS Media Schedule - Taylor Sabga
AS Media Schedule - Taylor SabgaAS Media Schedule - Taylor Sabga
AS Media Schedule - Taylor Sabga
 
Adaptive bank management[1]
Adaptive bank management[1]Adaptive bank management[1]
Adaptive bank management[1]
 
Jake
JakeJake
Jake
 
3 states of matter
3 states of matter3 states of matter
3 states of matter
 
Schedule REAL - taylor sabga
Schedule REAL -  taylor sabgaSchedule REAL -  taylor sabga
Schedule REAL - taylor sabga
 
A02 demoiselle
A02 demoiselleA02 demoiselle
A02 demoiselle
 
Transistores
TransistoresTransistores
Transistores
 
Shayna
ShaynaShayna
Shayna
 
Biznesa vadības sistēmas
Biznesa vadības sistēmas Biznesa vadības sistēmas
Biznesa vadības sistēmas
 
Digitize document management solution
Digitize document management solutionDigitize document management solution
Digitize document management solution
 
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumos
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumosAtvērtā pirmkoda programmatūra mazos un vidējos uzņēmumos
Atvērtā pirmkoda programmatūra mazos un vidējos uzņēmumos
 
Gv ie application question l
Gv ie application question lGv ie application question l
Gv ie application question l
 
OMalley_Profile
OMalley_ProfileOMalley_Profile
OMalley_Profile
 
This is what i do!!!!!
This is what i do!!!!!This is what i do!!!!!
This is what i do!!!!!
 
Pētījumi par IT lietošanu uzņēmumos
Pētījumi par IT lietošanu uzņēmumosPētījumi par IT lietošanu uzņēmumos
Pētījumi par IT lietošanu uzņēmumos
 
Digitize document management solution
Digitize document management solutionDigitize document management solution
Digitize document management solution
 
Splunk for AWS (Bagels and Bytes)
Splunk for AWS (Bagels and Bytes)Splunk for AWS (Bagels and Bytes)
Splunk for AWS (Bagels and Bytes)
 

Similar to Git of every day

How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day workAlena Radkevich
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4Davide Salvador
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanJames Ford
 
Git with the flow
Git with the flowGit with the flow
Git with the flowDana White
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of GitWayne Chen
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Ahmed El-Arabawy
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control systemKumaresh Chandra Baruri
 
Git Basics 1 Carenza
Git Basics 1 CarenzaGit Basics 1 Carenza
Git Basics 1 CarenzaPeter Carenza
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
SouthEast LinuxFest 2015 - intro to git
SouthEast LinuxFest 2015 -  intro to gitSouthEast LinuxFest 2015 -  intro to git
SouthEast LinuxFest 2015 - intro to gitedgester
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflowsArthur Shvetsov
 
Version control and GIT Primer
Version control and GIT PrimerVersion control and GIT Primer
Version control and GIT Primersaadulde
 

Similar to Git of every day (20)

How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day work
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Intro to Git
Intro to GitIntro to Git
Intro to Git
 
Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawan
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git Basics 1 Carenza
Git Basics 1 CarenzaGit Basics 1 Carenza
Git Basics 1 Carenza
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
SouthEast LinuxFest 2015 - intro to git
SouthEast LinuxFest 2015 -  intro to gitSouthEast LinuxFest 2015 -  intro to git
SouthEast LinuxFest 2015 - intro to git
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
 
Git It
Git ItGit It
Git It
 
Git training v10
Git training v10Git training v10
Git training v10
 
Version control and GIT Primer
Version control and GIT PrimerVersion control and GIT Primer
Version control and GIT Primer
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Git of every day

  • 1. of every day Notions and more Alan Descoins Tryolabs, 2014
  • 2. Goals ● Better understand what we do every day ● Ask less questions (understand the man) ● Improve some practices ● Make fewer mistakes ● Do something super specific ;)
  • 3. ● 2005, Linux kernel ● Efficiency, simple design ● Non-linear development (thousands of parallel branches) ● Completely distributed Origins and philosophy
  • 4. Distributed ● Nearly all operations are local ● All the machines have ALL the information ● Contrast with SVN, CVS, etc.
  • 5. Some theory ● git init initializes a repository ● Creates only one .git directory in the root (doesn’t pollute) ● Mini filesystem ● Snapshots, not differences!
  • 6. Git and the content ● Tracking of content, NOT files ● Vocabulary: tracked / untracked ● Git objects ○ Blob (content) ○ Tree (structure) ○ Commit (points to a tree, + data) ○ Tag (points to a commit, + data) SHA-1
  • 7. ● One file per “content” ● SHA-1 of the content (zlib) + a header ● Initially, loose object ● Then packfile (efficiency, heuristics…) ● Example: find .git/objects -type f Blob
  • 8. Tree ● Like a directory structure ● Pointers to blobs or other trees ● Represents a complete snapshot of the state ● Example: git ls-tree <sha-1>
  • 9. Commit ● Information about the trees ● Who, when, why saved the tree ● Points to the top level tree of the project ● Tree hierarchy ● Also SHA-1, different hash than the tree it points to
  • 11. Tags ● Pointer to a commit ● Additional information, signature ● So we don’t have to remember the SHA-1...
  • 12. The Holy Trinity A content may be in three states: ● Committed ● Modified ● Staged
  • 13. The Holy Trinity (2) Three parts of a project: ● Working directory ● Staging area (or index) ● .git (repository)
  • 14. Basic commands ● git add - adds to the index (staging) ● git commit - saves the index together with author, message, date, etc. ● git status - shows the file with differences between the working dir, staging, and the untracked ● git diff - what changed but is not staged ● git diff --cached - what is going in the next commit ● git log
  • 15. Avoiding the staging ● Sometimes, it may be easier to avoid the staging area ● git commit -a | git commit <archivo> ● Automatically add to the staging, then commit
  • 16. Branches ● Simply a pointer to a commit ● As fast as it is to write 41 characters to a file (SHA-1 + n) ● By default master ● Special pointer HEAD (current branch) ● Example: cat .git/HEAD
  • 17. Branches (2) ● git checkout to switch branches
  • 18. References ● The HEAD pointer is a special case ● Tags too: “an unmovable branch” (lightweight tags) Example: find .git/refs
  • 19. Remotes ● No central server ● Can add several remotes, external copies of the repo (URL) ● The famous origin :)
  • 20. Remote branches ● Save the state of branches in remote repositories ● They are local, but cannot be moved, only when you do network operations (eg. git fetch). ● The form is <remote>/<branch> Example: cat .git/refs/remotes/origin/master
  • 21. Fetch, push ● git fetch - sync and update remote branches (moves pointers) ● Eg. git fetch <remote> ● git pull - equivalent to git fetch and the git merge, merges the local branch with the changes in the remote ● git push - update the remote branch with the local data ● Eg. git push <remote> <branch>
  • 22. Tracking branches ● Local branches can “track” remote ones ● Two possibilities: ○ git checkout --track <remote>/<branch> ○ git push --set-upstream <remote> <branch> ● Now, when pushing you don’t have to type the name of the remote and the branch :)
  • 23. Merges ● Fast-forward: git is smart and only needs to move a pointer ● Integrate changes of one branch into another
  • 24. Merges (2) ● Three way merge: commit not direct ancestor of what I am merging in (non linear) ● Git determines the best common ancestor ● A merge commit is created, special because it has more than one parent ● Conflicts...
  • 26. Rebasing ● Another way to introduce changes of one branch into another ● Rewind & replay, rewrites the commits ● From a common ancestor ● History is always linear, even though it was work originally done in parallel
  • 27. Rebasing (2) ● git rebase <new-base> moves the commits from the current branch to the new base ● git rebase -i <new-base> lets us select actions for every commit ● git pull --rebase
  • 28. ● Never do rebase of a branch that is already pushed, or you pulled from somebody else ○ Duplicate commits if someone does merge ○ Arguable: if the remote branch is yours and used as backup ○ Use git push --force, if you are certain nobody else works in the branch ● If you rebase to get changes by other developers locally, do it as often as possible. Golden rules
  • 29. Rebase vs Merge Why rebase? ● Clean, linear history ● Open-source collaboration, many demand it ● Easier for code review Why merge? ● Easier to solve conflicts (only once) ● Less risk
  • 30. git reset ● Often used ● Used wrong, can cause loss of data (workdir unsafe) ● Three most used options: ○ --soft ○ --mixed ○ --hard
  • 31. git reset... ● move the branch HEAD points to so it points to target commit (stop if --soft) ● then make the staging look like that (stop if --mixed, default option) ● then make the working dir look like that (if --hard, it is workdir usafe!)
  • 32. Examples of git reset ● With HEAD in dev branch, do git reset master ○ now dev y master point to the same commit ● With HEAD in branch master, do git reset --hard origin/master ○ now my local master branch is identical to the remote (discard local changes) ● git reset --soft HEAD~ ○ Undo the last commit without losing changes
  • 33. Unstaging files ● When doing git reset <file> we don’t specify a branch or commit SHA ● Equivalent to git reset --mixed HEAD <file> ● Moves a particular file out of staging, opposite of git add :)
  • 34. git checkout ● git checkout <branch> is superficially similar to git reset --hard <branch> ● Two differences: ○ Workdir safe! :D Checks to avoid data loss. ○ reset moves the branch that HEAD points to, checkout moves the HEAD pointer itself.
  • 35. git checkout of a file ● git checkout <branch> <file> ○ As with reset, now it doesn’t make sense for it to move HEAD. Replaces only <file> in the workdir (workdir usafe!). ○ Would be the same as git reset --hard <branch> <file> ○ But that command does not exist :)
  • 36. Common situations (1) ● “I need to pull but there are changes I am working on, and I don’t want to commit yet” ○ git stash ○ It’s a stack ○ Apply with git stash pop.
  • 37. Common situations (2) ● “There is a bug in a branch, I need to know what commit introduced it” ○ git bisect ○ Binary search, driven by git. Very easy! ○ git bisect start git bisect bad <commit> git bisect good <commit> ● Test on every step (git makes a checkout)
  • 38. Common situations (3) ● “I made one (or several) commits in the wrong branch, haven’t yet pushed though!” ○ If the correct branch does not yet exist ■ git checkout -b <correct branch> ■ git reset over the old branch ○ If the branch already existed ■ git cherry-pick (or git rebase --onto) ■ git reset over the old branch
  • 39. Common situations (4) ● “I have many changes in a file and only want to commit some of them” ○ git add -p or git commit -p ○ git will ask for every part, whether to add it or not
  • 40. Common situations (5) ● “I need to change some commits” ● “I need to delete some commits” ● “I need to change the order of some commits” ○ git rebase -i (--interactive) ○ Easy to use ○ Rewrites history, asking us what to do for each commit
  • 41. Common situations (6) ● “I am doing a merge with many conflicts and I want to stop it and get back to where I was before” ○ git merge --abort
  • 42. (Images from git-scm and others ;) ) Didn’t learn git