SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
Get IT right
Git Kung Fu
Bartosz Majsak (@majson), Thomas Hug (@gizmoo360)

http://ctp.com
http://github.com/ctpconsulting
1

© 2013 Cambridge Technology Partners
Copyright © 2013 Cambridge Technology Partners All Rights Reserved. Cambridge, its logo, and Get IT Right are trademarks of Cambridge Technology Partners.
About Us


Bartosz Majsak
 Java

Developer by day
 Open source junkie by night (Arquillian core team member)
 Conference speaker by passion (Devoxx, Jazoon ...)



Thomas Hug
 With

Cambridge Technology Partners since 2002
 Java Developer, TTL, Solution Architect
 Apache Committer, OSS contributor and aficionado

2

© 2013 Cambridge Technology Partners

10/25/2013
Git Concepts



Performance and Efficiency



3

No Central Server – Distributed VCS

Robustness

© 2013 Cambridge Technology Partners

10/25/2013
Git Internals

© 2013 Cambridge Technology Partners
Git Architecture


Plumbing and Porcelain
 Composition

of low-level commands into high-level ones
 Unix design principles


Local as much as possible
git-add
git-commit
…

git-diff-index
git-update-server-info
git-check-ref-format
…
5

© 2013 Cambridge Technology Partners

10/25/2013
Git Storage


Delta storage vs. Directed Acyclic Graph (DAG)
C1

File A
Delta Storage
(SVN, Mercurial,…)

C2

C3

D1

C4

C5

D2
D1

File B

D2

File C

A1

A1

A2

A2

B

B

B

B1

B2

C

6

D2

A
DAG Storage
(Git, cp -r, …)

D1

C1

C2

C2

C3

© 2013 Cambridge Technology Partners

D3

10/25/2013
Git Storage – Object Model (1)


Git tracks content, not files



Content identified by 40 character SHA1 hash
 Modified

content easily identifiable
 Immutable in the object database


Objects: Blob, Tree, Commit, Tag



References: HEAD, Tags, Remotes
 Mutable,

pointers to commits

Empty directories are not considered as content.
Add an empty .gitignore if you need a folder tracked.

7

© 2013 Cambridge Technology Partners
Git Storage – Object Model (2)

├── lib
├
├── inc
├
├
└── tricks.rb
├
└── mylib.rc
└── README

8

© 2013 Cambridge Technology Partners
Git Storage – Local Repository


The repository .git directory

$ cd .git
$ tree -L 1
├── branches
├── config
├── description
├── HEAD
├── hooks
├── info
├── objects
└── refs
9

# Pointers to branches
# Repository local configuration
# Repository description

# Pointer to HEAD in current branch
# Pre- and post action hooks
# Additional information about the repository
# Object database
# Pointers to branches

© 2013 Cambridge Technology Partners

10/25/2013
Rewriting History

© 2013 Cambridge Technology Partners
Rebasing
$ git checkout master
$ git rebase mybranch

Rewriting history: Interactive rebase last four commits
$ git rebase --i HEAD~4

11

© 2013 Cambridge Technology Partners

git rebase
All your base are belong to us
Objectives: Learn how interactive rebasing works.


Experiment with interactive rebase on selected branch
 Reword

commit messages
 Combine commits into one

$ git rebase –i [commits range]

12

© 2013 Cambridge Technology Partners

10/25/2013
Cherry-pick
$ git cherry-pick [-x]

$ git cherry –v <other_branch>
Lets you check if given commit from other branch
has been already applied on the current branch

13

© 2013 Cambridge Technology Partners

Feature

Cherry-pick „replays” arbitrary commits onto
your current branch.

10/25/2013
Filter branch
$ git filter-branch



14

Removing a file from every commit
Changing commit metadata globally

© 2013 Cambridge Technology Partners

10/25/2013
Recovering from Mistakes

© 2013 Cambridge Technology Partners
Typos
Is there a way to fix poor commit messages?
$ git commit --amend
$ git rebase --i HEAD~X

16

© 2013 Cambridge Technology Partners

10/25/2013
Fixing Commits and Staging Area
For not yet pushed commits:
$ git commit --amend
Unstage a file:
$ git reset HEAD file.txt
Discard local changes:
$ git checkout -- file.txt
Fully revert to a previous commit:

$ git reset --hard HEAD

17

© 2013 Cambridge Technology Partners

git reset
Revert
$ git revert HEAD|hash|parent

Upgrading Library

Revert ‘Upgrading Library’

18

© 2013 Cambridge Technology Partners

git revert
One bridge too far
Disaster recovery.
What if...
$ git reset --hard HEAD^
$ git reflog
$ git reset --hard HEAD@{X}

19

© 2013 Cambridge Technology Partners

10/25/2013
Who broke the build?!
$ git blame FILE
$ git bisect start
$ git bisect bad
$ git bisect good <HASH>

20

© 2013 Cambridge Technology Partners

git blame
git bisect
Who broke the build?! - Pickaxe
$ git log –S'search_term' [-p] <resource>
$ git log –G'regex'

git log –S|G

--name-status
--pickaxe-all

21

© 2013 Cambridge Technology Partners
Sharing without network

© 2013 Cambridge Technology Partners
Archives
$ git archive --format zip --output "repo.zip" master

git archive

23

© 2013 Cambridge Technology Partners
Bundles
git bundle
$ git bundle create 
../jazoon.bundle master HEAD
$ git bundle create <filename> <refs ...>
$ git bundle create ../jazoon.bundle 
--since="one week ago" master
$ git bundle verify /tmp/jazoon.bundle
$ git pull /tmp/ejmr.bundle master:master

You can also add a bundle as a remote:

$ git remote add bundle /path/to/bundle.bundle

24

© 2013 Cambridge Technology Partners
Repeat Yourself
Repeat Yourself
Repeat Yourself

© 2013 Cambridge Technology Partners
Reuse Recorded Resolution (ReReRe)
$ git config rerere.enabled true
… # create a merge conflict
git rerere
$ git rerere status
$ git rerere diff
… # resolve conflict
$ git rerere diff
… # commit, reset hard HEAD^1, redo merge

Evict old recorded resolutions from repository:
$ git rerere gc

26

© 2013 Cambridge Technology Partners

10/25/2013
Other tricks

© 2013 Cambridge Technology Partners
Sparse Checkouts
$ git init
$ git config core.sparsecheckout true
$ echo path/to/checkout 
>> .git/info/sparse-checkout
$ git remote add -f origin ...
$ git pull origin ...

You can also push to sparse checkout repositories

28

© 2013 Cambridge Technology Partners

10/25/2013
Orphan Branches

??

$ git checkout --orphan [branch]
$ git rm -rf *
Use for:
 Documentation (combine with hooks or CI server!)
 Resources

Have a look at the GitHub gh-pages for some ideas
what orphan branches can do.

29

© 2013 Cambridge Technology Partners

10/25/2013
Notes
Annotates existing commits.
$ git notes add HEAD
$ git notes add –m’Fixes everything’ HEAD
$ git notes --ref=jazoon edit master~1
$ git push origin refs/notes/jazoon

30

© 2013 Cambridge Technology Partners

10/25/2013
Other goodies
$ git diff --word-diff --color-words
$ git config --global help.autocorrect 1
$ git rebase -i --autosquash HEAD~3
Commit message should contain squash! or fixup! as message prefix and
title or hash of target commit

31

© 2013 Cambridge Technology Partners

10/25/2013
Hooks

© 2013 Cambridge Technology Partners
Git hooks
$ cd .git/hooks
Client-side
 pre-commit
 prepare-commit-msg
 commit-msg

 post-commit

Server-side
 pre-receive
 post-receive
 update

33

© 2013 Cambridge Technology Partners

10/25/2013
Workflows

© 2013 Cambridge Technology Partners
Git Flow
$ git flow init
master

35

hotfix

release

git flow
develop

© 2013 Cambridge Technology Partners

Feature branches
Git in the Enterprise

© 2013 Cambridge Technology Partners
Get IT right
Thank you!

37

© 2013 Cambridge Technology Partners
Credits


38

Icons provided by Icons8: http://icons8.com/

© 2013 Cambridge Technology Partners

10/25/2013

Contenu connexe

En vedette

Learning git
Learning gitLearning git
Learning gitSid Anand
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GITZeeshan Khan
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Paradigma Digital
 
A proven path for migrating from clearcase to git and or subversion
A proven path for migrating from clearcase to git and or subversionA proven path for migrating from clearcase to git and or subversion
A proven path for migrating from clearcase to git and or subversionCollabNet
 
Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4Git intermediate workshop slides v1.4
Git intermediate workshop slides v1.4Davide Salvador
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to gitJoel Krebs
 

En vedette (16)

Git scm
Git scmGit scm
Git scm
 
Tech thursdays / GIT
Tech thursdays / GITTech thursdays / GIT
Tech thursdays / GIT
 
Learning git
Learning gitLearning git
Learning git
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?
 
A proven path for migrating from clearcase to git and or subversion
A proven path for migrating from clearcase to git and or subversionA proven path for migrating from clearcase to git and or subversion
A proven path for migrating from clearcase to git and or subversion
 
Git
GitGit
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 Introduction
Git IntroductionGit Introduction
Git Introduction
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Intro To Git
Intro To GitIntro To Git
Intro To Git
 
Git Presentation
Git PresentationGit Presentation
Git Presentation
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Getting Git
Getting GitGetting Git
Getting Git
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 

Similaire à Git Kung Fu: Mastering Git with Rebasing, Cherry-Picking and More

Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlBecky Todd
 
That's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICThat's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICLa FeWeb
 
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceGTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceForest Mars
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in UnityRifauddin Tsalitsy
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control SystemVictor Wong
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GITArpit Mohan
 
Why Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysWhy Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysCarlos Taborda
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 
A Quick Start - Version Control with Git
A Quick Start - Version Control with GitA Quick Start - Version Control with Git
A Quick Start - Version Control with GitDmitry Sheiko
 
GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807Shota Ito
 

Similaire à Git Kung Fu: Mastering Git with Rebasing, Cherry-Picking and More (20)

Git and Github
Git and GithubGit and Github
Git and Github
 
Git and github
Git and githubGit and github
Git and github
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
That's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICThat's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETIC
 
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceGTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Geek git
Geek gitGeek git
Geek git
 
Git presentation
Git presentationGit presentation
Git presentation
 
Git
GitGit
Git
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Why Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysWhy Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anyways
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Gittalk
GittalkGittalk
Gittalk
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 
A Quick Start - Version Control with Git
A Quick Start - Version Control with GitA Quick Start - Version Control with Git
A Quick Start - Version Control with Git
 
Git
GitGit
Git
 
GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807
 

Plus de jazoon13

JAZOON'13 - Joe Justice - Test First Saves The World
JAZOON'13 - Joe Justice - Test First Saves The WorldJAZOON'13 - Joe Justice - Test First Saves The World
JAZOON'13 - Joe Justice - Test First Saves The Worldjazoon13
 
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Stories
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User StoriesJAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Stories
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Storiesjazoon13
 
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScript
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScriptJAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScript
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScriptjazoon13
 
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone beforeJAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone beforejazoon13
 
JAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled JavaJAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled Javajazoon13
 
JAZOON'13 - Sven Peters - How to do Kick-Ass Software Development
JAZOON'13 - Sven Peters - How to do Kick-Ass Software DevelopmentJAZOON'13 - Sven Peters - How to do Kick-Ass Software Development
JAZOON'13 - Sven Peters - How to do Kick-Ass Software Developmentjazoon13
 
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...jazoon13
 
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teams
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed TeamsJAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teams
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teamsjazoon13
 
JAZOON'13 - Kai Waehner - Hadoop Integration
JAZOON'13 - Kai Waehner - Hadoop IntegrationJAZOON'13 - Kai Waehner - Hadoop Integration
JAZOON'13 - Kai Waehner - Hadoop Integrationjazoon13
 
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next GenerationJAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generationjazoon13
 
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtime
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In RealtimeJAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtime
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtimejazoon13
 
JAZOON'13 - Andrej Vckovski - Go synchronized
JAZOON'13 - Andrej Vckovski - Go synchronizedJAZOON'13 - Andrej Vckovski - Go synchronized
JAZOON'13 - Andrej Vckovski - Go synchronizedjazoon13
 
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experienceJAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experiencejazoon13
 
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !jazoon13
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Softwarejazoon13
 
JAZOON'13 - Stefan Saasen - True Git: The Great Migration
JAZOON'13 - Stefan Saasen - True Git: The Great MigrationJAZOON'13 - Stefan Saasen - True Git: The Great Migration
JAZOON'13 - Stefan Saasen - True Git: The Great Migrationjazoon13
 
JAZOON'13 - Stefan Saasen - Real World Git Workflows
JAZOON'13 - Stefan Saasen - Real World Git WorkflowsJAZOON'13 - Stefan Saasen - Real World Git Workflows
JAZOON'13 - Stefan Saasen - Real World Git Workflowsjazoon13
 

Plus de jazoon13 (17)

JAZOON'13 - Joe Justice - Test First Saves The World
JAZOON'13 - Joe Justice - Test First Saves The WorldJAZOON'13 - Joe Justice - Test First Saves The World
JAZOON'13 - Joe Justice - Test First Saves The World
 
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Stories
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User StoriesJAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Stories
JAZOON'13 - Ulrika Park- User Story telling The Lost Art of User Stories
 
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScript
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScriptJAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScript
JAZOON'13 - Oliver Zeigermann - Typed JavaScript with TypeScript
 
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone beforeJAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
 
JAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled JavaJAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled Java
 
JAZOON'13 - Sven Peters - How to do Kick-Ass Software Development
JAZOON'13 - Sven Peters - How to do Kick-Ass Software DevelopmentJAZOON'13 - Sven Peters - How to do Kick-Ass Software Development
JAZOON'13 - Sven Peters - How to do Kick-Ass Software Development
 
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
 
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teams
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed TeamsJAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teams
JAZOON'13 - Pawel Wrzeszcz - Visibility Shift In Distributed Teams
 
JAZOON'13 - Kai Waehner - Hadoop Integration
JAZOON'13 - Kai Waehner - Hadoop IntegrationJAZOON'13 - Kai Waehner - Hadoop Integration
JAZOON'13 - Kai Waehner - Hadoop Integration
 
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next GenerationJAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
 
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtime
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In RealtimeJAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtime
JAZOON'13 - Guide Schmutz - Kafka and Strom Event Processing In Realtime
 
JAZOON'13 - Andrej Vckovski - Go synchronized
JAZOON'13 - Andrej Vckovski - Go synchronizedJAZOON'13 - Andrej Vckovski - Go synchronized
JAZOON'13 - Andrej Vckovski - Go synchronized
 
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experienceJAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
 
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
 
JAZOON'13 - Stefan Saasen - True Git: The Great Migration
JAZOON'13 - Stefan Saasen - True Git: The Great MigrationJAZOON'13 - Stefan Saasen - True Git: The Great Migration
JAZOON'13 - Stefan Saasen - True Git: The Great Migration
 
JAZOON'13 - Stefan Saasen - Real World Git Workflows
JAZOON'13 - Stefan Saasen - Real World Git WorkflowsJAZOON'13 - Stefan Saasen - Real World Git Workflows
JAZOON'13 - Stefan Saasen - Real World Git Workflows
 

Dernier

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Dernier (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Git Kung Fu: Mastering Git with Rebasing, Cherry-Picking and More

  • 1. Get IT right Git Kung Fu Bartosz Majsak (@majson), Thomas Hug (@gizmoo360) http://ctp.com http://github.com/ctpconsulting 1 © 2013 Cambridge Technology Partners Copyright © 2013 Cambridge Technology Partners All Rights Reserved. Cambridge, its logo, and Get IT Right are trademarks of Cambridge Technology Partners.
  • 2. About Us  Bartosz Majsak  Java Developer by day  Open source junkie by night (Arquillian core team member)  Conference speaker by passion (Devoxx, Jazoon ...)  Thomas Hug  With Cambridge Technology Partners since 2002  Java Developer, TTL, Solution Architect  Apache Committer, OSS contributor and aficionado 2 © 2013 Cambridge Technology Partners 10/25/2013
  • 3. Git Concepts   Performance and Efficiency  3 No Central Server – Distributed VCS Robustness © 2013 Cambridge Technology Partners 10/25/2013
  • 4. Git Internals © 2013 Cambridge Technology Partners
  • 5. Git Architecture  Plumbing and Porcelain  Composition of low-level commands into high-level ones  Unix design principles  Local as much as possible git-add git-commit … git-diff-index git-update-server-info git-check-ref-format … 5 © 2013 Cambridge Technology Partners 10/25/2013
  • 6. Git Storage  Delta storage vs. Directed Acyclic Graph (DAG) C1 File A Delta Storage (SVN, Mercurial,…) C2 C3 D1 C4 C5 D2 D1 File B D2 File C A1 A1 A2 A2 B B B B1 B2 C 6 D2 A DAG Storage (Git, cp -r, …) D1 C1 C2 C2 C3 © 2013 Cambridge Technology Partners D3 10/25/2013
  • 7. Git Storage – Object Model (1)  Git tracks content, not files  Content identified by 40 character SHA1 hash  Modified content easily identifiable  Immutable in the object database  Objects: Blob, Tree, Commit, Tag  References: HEAD, Tags, Remotes  Mutable, pointers to commits Empty directories are not considered as content. Add an empty .gitignore if you need a folder tracked. 7 © 2013 Cambridge Technology Partners
  • 8. Git Storage – Object Model (2) ├── lib ├ ├── inc ├ ├ └── tricks.rb ├ └── mylib.rc └── README 8 © 2013 Cambridge Technology Partners
  • 9. Git Storage – Local Repository  The repository .git directory $ cd .git $ tree -L 1 ├── branches ├── config ├── description ├── HEAD ├── hooks ├── info ├── objects └── refs 9 # Pointers to branches # Repository local configuration # Repository description # Pointer to HEAD in current branch # Pre- and post action hooks # Additional information about the repository # Object database # Pointers to branches © 2013 Cambridge Technology Partners 10/25/2013
  • 10. Rewriting History © 2013 Cambridge Technology Partners
  • 11. Rebasing $ git checkout master $ git rebase mybranch Rewriting history: Interactive rebase last four commits $ git rebase --i HEAD~4 11 © 2013 Cambridge Technology Partners git rebase
  • 12. All your base are belong to us Objectives: Learn how interactive rebasing works.  Experiment with interactive rebase on selected branch  Reword commit messages  Combine commits into one $ git rebase –i [commits range] 12 © 2013 Cambridge Technology Partners 10/25/2013
  • 13. Cherry-pick $ git cherry-pick [-x] $ git cherry –v <other_branch> Lets you check if given commit from other branch has been already applied on the current branch 13 © 2013 Cambridge Technology Partners Feature Cherry-pick „replays” arbitrary commits onto your current branch. 10/25/2013
  • 14. Filter branch $ git filter-branch   14 Removing a file from every commit Changing commit metadata globally © 2013 Cambridge Technology Partners 10/25/2013
  • 15. Recovering from Mistakes © 2013 Cambridge Technology Partners
  • 16. Typos Is there a way to fix poor commit messages? $ git commit --amend $ git rebase --i HEAD~X 16 © 2013 Cambridge Technology Partners 10/25/2013
  • 17. Fixing Commits and Staging Area For not yet pushed commits: $ git commit --amend Unstage a file: $ git reset HEAD file.txt Discard local changes: $ git checkout -- file.txt Fully revert to a previous commit: $ git reset --hard HEAD 17 © 2013 Cambridge Technology Partners git reset
  • 18. Revert $ git revert HEAD|hash|parent Upgrading Library Revert ‘Upgrading Library’ 18 © 2013 Cambridge Technology Partners git revert
  • 19. One bridge too far Disaster recovery. What if... $ git reset --hard HEAD^ $ git reflog $ git reset --hard HEAD@{X} 19 © 2013 Cambridge Technology Partners 10/25/2013
  • 20. Who broke the build?! $ git blame FILE $ git bisect start $ git bisect bad $ git bisect good <HASH> 20 © 2013 Cambridge Technology Partners git blame git bisect
  • 21. Who broke the build?! - Pickaxe $ git log –S'search_term' [-p] <resource> $ git log –G'regex' git log –S|G --name-status --pickaxe-all 21 © 2013 Cambridge Technology Partners
  • 22. Sharing without network © 2013 Cambridge Technology Partners
  • 23. Archives $ git archive --format zip --output "repo.zip" master git archive 23 © 2013 Cambridge Technology Partners
  • 24. Bundles git bundle $ git bundle create ../jazoon.bundle master HEAD $ git bundle create <filename> <refs ...> $ git bundle create ../jazoon.bundle --since="one week ago" master $ git bundle verify /tmp/jazoon.bundle $ git pull /tmp/ejmr.bundle master:master You can also add a bundle as a remote: $ git remote add bundle /path/to/bundle.bundle 24 © 2013 Cambridge Technology Partners
  • 25. Repeat Yourself Repeat Yourself Repeat Yourself © 2013 Cambridge Technology Partners
  • 26. Reuse Recorded Resolution (ReReRe) $ git config rerere.enabled true … # create a merge conflict git rerere $ git rerere status $ git rerere diff … # resolve conflict $ git rerere diff … # commit, reset hard HEAD^1, redo merge Evict old recorded resolutions from repository: $ git rerere gc 26 © 2013 Cambridge Technology Partners 10/25/2013
  • 27. Other tricks © 2013 Cambridge Technology Partners
  • 28. Sparse Checkouts $ git init $ git config core.sparsecheckout true $ echo path/to/checkout >> .git/info/sparse-checkout $ git remote add -f origin ... $ git pull origin ... You can also push to sparse checkout repositories 28 © 2013 Cambridge Technology Partners 10/25/2013
  • 29. Orphan Branches ?? $ git checkout --orphan [branch] $ git rm -rf * Use for:  Documentation (combine with hooks or CI server!)  Resources Have a look at the GitHub gh-pages for some ideas what orphan branches can do. 29 © 2013 Cambridge Technology Partners 10/25/2013
  • 30. Notes Annotates existing commits. $ git notes add HEAD $ git notes add –m’Fixes everything’ HEAD $ git notes --ref=jazoon edit master~1 $ git push origin refs/notes/jazoon 30 © 2013 Cambridge Technology Partners 10/25/2013
  • 31. Other goodies $ git diff --word-diff --color-words $ git config --global help.autocorrect 1 $ git rebase -i --autosquash HEAD~3 Commit message should contain squash! or fixup! as message prefix and title or hash of target commit 31 © 2013 Cambridge Technology Partners 10/25/2013
  • 32. Hooks © 2013 Cambridge Technology Partners
  • 33. Git hooks $ cd .git/hooks Client-side  pre-commit  prepare-commit-msg  commit-msg  post-commit Server-side  pre-receive  post-receive  update 33 © 2013 Cambridge Technology Partners 10/25/2013
  • 34. Workflows © 2013 Cambridge Technology Partners
  • 35. Git Flow $ git flow init master 35 hotfix release git flow develop © 2013 Cambridge Technology Partners Feature branches
  • 36. Git in the Enterprise © 2013 Cambridge Technology Partners
  • 37. Get IT right Thank you! 37 © 2013 Cambridge Technology Partners
  • 38. Credits  38 Icons provided by Icons8: http://icons8.com/ © 2013 Cambridge Technology Partners 10/25/2013