SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Más 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
 

Más 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
 

Último

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Último (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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