SlideShare a Scribd company logo
1 of 49
Download to read offline
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Advanced Git Techniques
Subtrees, grafting and other fun
Get more out of your
version control.
Today we’ll cover some powerful Git goodies
Interactive stagingPainless sub-projects Collating history
Interactive commits are
an amazing tool at your
disposal as you work on
complex code changes
You can use git
subtree to handle
external libraries in a
clean and efficient way
Joining together history
of your projects using
git replace is useful
when migrating to Git
git subtree
Extract project
Alternative to git submodule to handle
external dependencies.
Inject dependency
It allows you to inject an external
project into a sub-folder
Introduced in 1.7.11
It can be also used to extract a
sub-folder as separate project
Clean integration pointsStores in regular commitsNo training
When and why is git subtree a great choice
Does not require your
entire team to be
trained in the use of the
command
The command stores
the external
dependency in regular
Git commits. Squashing
the history optionally.
It makes it easy to see
when integrations
happened and makes it
easy to revert them.
Syntax to inject a project
Command to inject project
git subtree add 
--prefix target-folder 
https://bitbucket.org/team/sub.git 
master --squash
Folder where to insert code
Repository URL
v1.1
Under the hood of git subtree
commit ab54c4e0b75c3107e3e773ab9b39268abddca002
Author: Nicola Paolucci <npaolucci@atlassian.com>
Date: Tue Sep 29 15:27:35 2015 +0200
Squashed ‘src/sub-project‘ content from commit df563ed
git-subtree-dir: src/sub-project
git-subtree-split: df563ed15fa6…6b2e95d3
Result of git subtree add
commit 8fb507baf7b270c30c822b27e262d0b44819b4c5
Merge: 606cd3e ab54c4e
Author: Nicola Paolucci <npaolucci@atlassian.com>
Date: Tue Sep 29 15:27:35 2015 +0200
Merge commit 'ab54c4e0b75c3107e3e773ab9b39268abddca002' as '.vim/bundle/fireplace'
commit ab54c4e0b75c3107e3e773ab9b39268abddca002
Author: Nicola Paolucci <npaolucci@atlassian.com>
Date: Tue Sep 29 15:27:35 2015 +0200
Squashed '.vim/bundle/fireplace/' content from commit df563ed
git-subtree-dir: .vim/bundle/fireplace
git-subtree-split: df563ed15fa685ce2508bf16b3ca7e176b2e95d3
To keep the sub-project up to date
git subtree pull 
--prefix target-folder 
https://bitbucket.org/team/sub.git 
master --squash
Command to pull project
Folder where to insert code
Repository URL
v1.5
Under the hood of git subtree
commit ab54c4e0b75c3107e3e773ab9b39268abddca002
Author: Nicola Paolucci <npaolucci@atlassian.com>
Date: Tue Sep 29 15:27:35 2015 +0200
Squashed ‘src/sub-project‘ content from commit df563ed
git-subtree-dir: src/sub-project
git-subtree-split: df563ed15fa6…6b2e95d3
Find the symbolic ref matching a hash (sha-1)
sha-1 of last commit pulled
Git plumbing to list all remote refs
Repository URL
git ls-remote https://bitbucket.org/team/sub.git | grep df563ed
df563ed15fa685ce2508bf16b3ca7e176b2e95d3 v1.1
5eaff1232acedeca565er7e1333234dacccebfff v1.5
git ls-remote https://bitbucket.org/team/sub.git | grep <sha-1>
Aliases to make your life easier!
[alias]
sba = "!f() { git subtree add --prefix $2 $1 master --squash; }; f"
sbu = "!f() { git subtree pull --prefix $2 $1 master --squash; }; f"
Alias section of your .gitconfig
http://bit.do/git-aliases
How to use the aliases
git sba <repo URL> <destination-folder>
git sba https://bitbucket.org/team/sub.git src/sub
When everyone in the
team must work on
sub-projects
When you have
constant updates to
your dependencies
When you have many
dependencies
When NOT to use git subtree
For complex project dependencies
Use a dependency tool.
Really.
Alternatives?
Read my rant
on project
dependencies
http://bit.do/git-dep
How to extract a project
Let’s learn how to use subtree split
Git subtree to extract a project
Command to split out project
git subtree split 
--prefix my/project/ 
--branch extracted
Folder prefix to extract
where we store it
Push to new remote
We can remove the contents of the
folder from the repo
Import extracted branch
Initialise a new repo and import the
extracted branch
Remove from old repo
After we imported the code we can
push it to a new repository
git rm -rf my/project
git init
git pull ../path/ extracted
git remote add origin …
git push origin -u master
Interactive commit
Splitting commits semantically in flight!
Fine grained control on
your commits
Knowing this technique
frees you from worrying
about what to do first
Atomic commits make
your changes readable
Why split changes interactively?
We modify a single file (README) in 3 parts
# Title
Content of my article
## Subtitle second heading
Some more paragraph content
## Conclusions
We modify a single file in 3 different parts
[:~/p/demo] master(+3/-0) ± git diff
@@ -1,11 +1,14 @@
# Title
Content of my article
+Adding a second line to Title.
## Subtitle second heading
Some more paragraph content
+Adding another line to Subtitle 1
## Conclusions
Here are your conclusions
To split those changes in separate commits:
git commit --interactive
staged unstaged path
1: unchanged +3/-0 README.md
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now>
Overview of
interactive
staging
revert
The status of the files, whether they
are staged or unstaged.
update
Choose which files to add to the
staging area
status
Undo any action done previously in
this session.
Overview of
interactive
staging [2]
add untracked
Check the unstaged or staged
changes in the workspace.
patch
Add parts of a file to the staging area.
This allows you to split commits.
diff
Add new untracked files to the
repository.
I finally hit “p” for patch, select the file and ENTER:
What now> p
staged unstaged path
1: unchanged +3/-0 README.md
Patch update>> 1
staged unstaged path
* 1: unchanged +3/-0 README.md
Patch update>>
I finally hit “p” for patch, select the file and ENTER:
@@ -1,11 +1,14 @@
# Title
Content of my article
+Adding a second line to Title.
## Subtitle second heading
Some more paragraph content
+Adding another line to Subtitle 1
## Conclusions
Here are your conclusions
+Adding to the Conclusions.
Stage this
hunk?!?!
A hunk is just a piece of text in a larger file.
Diff and patch commands tend to understand
changes by clustering them in blocks of
continuous text.
“
”
If the default hunk size is too big, you can split it:
Stage this hunk [y,n,q,a,d,/,s,e,?]? s
Split into 3 hunks.
@@ -1,7 +1,8 @@
# Title
Content of my article
+Adding a second line to Title.
## Subtitle second heading
Some more paragraph content
Let’s stage this hunk, or add it to the staging area:
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
@@ -4,8 +5,9 @@
## Subtitle second heading
Some more paragraph content
+Adding another line to Subtitle 1
## Conclusions
Here are your conclusions
Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]?
Now so skip all the rest pressing “q” twice:
The result is a neat new commit and the rest left:
14a0be4 [4 minutes ago] (HEAD -> master) Add content to Title [Nick]
git diff
diff --git i/README.md w/README.md
index fc26295..0ef85c4 100644
--- i/README.md
+++ w/README.md
@@ -6,7 +6,9 @@ Adding a second line to Title.
## Subtitle second heading
Some more paragraph content
+Adding another line to Subtitle 1
## Conclusions
When you need help just press “?”
Stage this hunk [y,n,q,a,d,/,s,e,?]? ?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
Collating History
Cross VCS mergesUnify two reposFast migration from svn
Why collate history?
Migrate immediately
from Subversion, attach
the earlier history after
the migration.
You have two
repositories that should
actually be only one.
You need to perform
Subversion merges in a
Git branch
One relevant
example:
Linux kernel
Today use git replace
The entire history of the Linux kernel
is split over three different repos.
Originally in Grafts
Which are local pair of ids connecting
a commit id (SHA-1) to the next
Linux kernel is split
Available in the stock git distribution
since version 1.6.5
git replace is capable to replace any object
with any other object.
It tracks these swaps via refs which you can
push and pull between repositories.
“
”
git replace in practice
shallow
first
last
legacy
shallow clone with cut history
git replace first last
First commit of restarted repo
git checkout -b shallow origin/shallow
git log --max-parents=0 master
git tag 56eacf first -m”Tag… commit”
shallow
first
Last commit of legacy repo
git checkout -b legacy origin/legacy
git rev-parse --verify legacy
git tag 84abb last -m”Tag… commit”
last
legacy
git replace in practice
shallow
first
last
legacy
shallow clone with cut history
git replace first last
Replacements are persisted
cat .git/refs/replace/56eac…7cc
84abb39d9aab234dfba2e41f13f693fa5edbfe22
git push origin ‘refs/replace/*’
If you want to make the git replace changes
permanent and free the team from pulling
those refs, do a final pass using
git filter-branch
“
”
Go forth and enrich your
Git experience
Thank you!
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Twitter: @durdn
• GIF backdrops taken from giphy.com
• Icons from thenounproject.com credits below
Image credits

More Related Content

What's hot

Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagramsDilum Navanjana
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control SystemKMS Technology
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Minicurso GIT Completo (2022)
Minicurso GIT Completo (2022)Minicurso GIT Completo (2022)
Minicurso GIT Completo (2022)Danilo Pinotti
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitColin Su
 
이클립스로 GIT 사용하기
이클립스로 GIT 사용하기이클립스로 GIT 사용하기
이클립스로 GIT 사용하기우영 주
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the RESTRoy Clarkson
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 

What's hot (20)

Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git training v10
Git training v10Git training v10
Git training v10
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Git
GitGit
Git
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Minicurso GIT Completo (2022)
Minicurso GIT Completo (2022)Minicurso GIT Completo (2022)
Minicurso GIT Completo (2022)
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
이클립스로 GIT 사용하기
이클립스로 GIT 사용하기이클립스로 GIT 사용하기
이클립스로 GIT 사용하기
 
git and github
git and githubgit and github
git and github
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the REST
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git basic
Git basicGit basic
Git basic
 

Viewers also liked

Cregit Recovering token level authorship from Git
Cregit Recovering token level authorship from GitCregit Recovering token level authorship from Git
Cregit Recovering token level authorship from Gitdmgerman
 
Anatomy 210 abdomen & pelvis for semester ii year 2012-2013
Anatomy 210 abdomen & pelvis   for semester ii year 2012-2013Anatomy 210 abdomen & pelvis   for semester ii year 2012-2013
Anatomy 210 abdomen & pelvis for semester ii year 2012-2013AHS_anatomy2
 
Cross Sectional Anatomy Of The Abdomen Annotated
Cross Sectional Anatomy Of The Abdomen AnnotatedCross Sectional Anatomy Of The Abdomen Annotated
Cross Sectional Anatomy Of The Abdomen AnnotatedDebby Edney
 
Nmt 405 abdomen and pelvis ppt
Nmt 405 abdomen and pelvis pptNmt 405 abdomen and pelvis ppt
Nmt 405 abdomen and pelvis pptClassyCJ
 
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.Presentation1.pptx, radiological anatomy of the abdomen and pelvis.
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.Abdellah Nazeer
 

Viewers also liked (10)

Cregit Recovering token level authorship from Git
Cregit Recovering token level authorship from GitCregit Recovering token level authorship from Git
Cregit Recovering token level authorship from Git
 
Abdominal CT scan
Abdominal CT scanAbdominal CT scan
Abdominal CT scan
 
Anatomy abdomen and pelvis
Anatomy abdomen and pelvis Anatomy abdomen and pelvis
Anatomy abdomen and pelvis
 
CT ABDOMEN ANATOMY
 CT ABDOMEN ANATOMY CT ABDOMEN ANATOMY
CT ABDOMEN ANATOMY
 
Anatomy 210 abdomen & pelvis for semester ii year 2012-2013
Anatomy 210 abdomen & pelvis   for semester ii year 2012-2013Anatomy 210 abdomen & pelvis   for semester ii year 2012-2013
Anatomy 210 abdomen & pelvis for semester ii year 2012-2013
 
Cross Sectional Anatomy Of The Abdomen Annotated
Cross Sectional Anatomy Of The Abdomen AnnotatedCross Sectional Anatomy Of The Abdomen Annotated
Cross Sectional Anatomy Of The Abdomen Annotated
 
Nmt 405 abdomen and pelvis ppt
Nmt 405 abdomen and pelvis pptNmt 405 abdomen and pelvis ppt
Nmt 405 abdomen and pelvis ppt
 
BASICS of CT Head
BASICS of CT HeadBASICS of CT Head
BASICS of CT Head
 
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.Presentation1.pptx, radiological anatomy of the abdomen and pelvis.
Presentation1.pptx, radiological anatomy of the abdomen and pelvis.
 
CT Anatomy
CT AnatomyCT Anatomy
CT Anatomy
 

Similar to Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff

Transformative Git Practices
Transformative Git PracticesTransformative Git Practices
Transformative Git PracticesNicola Paolucci
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Take the next step with git
Take the next step with gitTake the next step with git
Take the next step with gitKarin Taliga
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheetLam Hoang
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03Gourav Varma
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
Rc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocidoRc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocidoLuis Bertel
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for ArtistsDavid Newbury
 

Similar to Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff (20)

Transformative Git Practices
Transformative Git PracticesTransformative Git Practices
Transformative Git Practices
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git training
Git trainingGit training
Git training
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Take the next step with git
Take the next step with gitTake the next step with git
Take the next step with git
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheet
 
Git slides
Git slidesGit slides
Git slides
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Rc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocidoRc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocido
 
Git more done
Git more doneGit more done
Git more done
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 

More from Atlassian

International Women's Day 2020
International Women's Day 2020International Women's Day 2020
International Women's Day 2020Atlassian
 
10 emerging trends that will unbreak your workplace in 2020
10 emerging trends that will unbreak your workplace in 202010 emerging trends that will unbreak your workplace in 2020
10 emerging trends that will unbreak your workplace in 2020Atlassian
 
Forge App Showcase
Forge App ShowcaseForge App Showcase
Forge App ShowcaseAtlassian
 
Let's Build an Editor Macro with Forge UI
Let's Build an Editor Macro with Forge UILet's Build an Editor Macro with Forge UI
Let's Build an Editor Macro with Forge UIAtlassian
 
Meet the Forge Runtime
Meet the Forge RuntimeMeet the Forge Runtime
Meet the Forge RuntimeAtlassian
 
Forge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User ExperienceForge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User ExperienceAtlassian
 
Take Action with Forge Triggers
Take Action with Forge TriggersTake Action with Forge Triggers
Take Action with Forge TriggersAtlassian
 
Observability and Troubleshooting in Forge
Observability and Troubleshooting in ForgeObservability and Troubleshooting in Forge
Observability and Troubleshooting in ForgeAtlassian
 
Trusted by Default: The Forge Security & Privacy Model
Trusted by Default: The Forge Security & Privacy ModelTrusted by Default: The Forge Security & Privacy Model
Trusted by Default: The Forge Security & Privacy ModelAtlassian
 
Designing Forge UI: A Story of Designing an App UI System
Designing Forge UI: A Story of Designing an App UI SystemDesigning Forge UI: A Story of Designing an App UI System
Designing Forge UI: A Story of Designing an App UI SystemAtlassian
 
Forge: Under the Hood
Forge: Under the HoodForge: Under the Hood
Forge: Under the HoodAtlassian
 
Access to User Activities - Activity Platform APIs
Access to User Activities - Activity Platform APIsAccess to User Activities - Activity Platform APIs
Access to User Activities - Activity Platform APIsAtlassian
 
Design Your Next App with the Atlassian Vendor Sketch Plugin
Design Your Next App with the Atlassian Vendor Sketch PluginDesign Your Next App with the Atlassian Vendor Sketch Plugin
Design Your Next App with the Atlassian Vendor Sketch PluginAtlassian
 
Tear Up Your Roadmap and Get Out of the Building
Tear Up Your Roadmap and Get Out of the BuildingTear Up Your Roadmap and Get Out of the Building
Tear Up Your Roadmap and Get Out of the BuildingAtlassian
 
Nailing Measurement: a Framework for Measuring Metrics that Matter
Nailing Measurement: a Framework for Measuring Metrics that MatterNailing Measurement: a Framework for Measuring Metrics that Matter
Nailing Measurement: a Framework for Measuring Metrics that MatterAtlassian
 
Building Apps With Color Blind Users in Mind
Building Apps With Color Blind Users in MindBuilding Apps With Color Blind Users in Mind
Building Apps With Color Blind Users in MindAtlassian
 
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...Atlassian
 
Beyond Diversity: A Guide to Building Balanced Teams
Beyond Diversity: A Guide to Building Balanced TeamsBeyond Diversity: A Guide to Building Balanced Teams
Beyond Diversity: A Guide to Building Balanced TeamsAtlassian
 
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed Team
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed TeamThe Road(map) to Las Vegas - The Story of an Emerging Self-Managed Team
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed TeamAtlassian
 
Building Apps With Enterprise in Mind
Building Apps With Enterprise in MindBuilding Apps With Enterprise in Mind
Building Apps With Enterprise in MindAtlassian
 

More from Atlassian (20)

International Women's Day 2020
International Women's Day 2020International Women's Day 2020
International Women's Day 2020
 
10 emerging trends that will unbreak your workplace in 2020
10 emerging trends that will unbreak your workplace in 202010 emerging trends that will unbreak your workplace in 2020
10 emerging trends that will unbreak your workplace in 2020
 
Forge App Showcase
Forge App ShowcaseForge App Showcase
Forge App Showcase
 
Let's Build an Editor Macro with Forge UI
Let's Build an Editor Macro with Forge UILet's Build an Editor Macro with Forge UI
Let's Build an Editor Macro with Forge UI
 
Meet the Forge Runtime
Meet the Forge RuntimeMeet the Forge Runtime
Meet the Forge Runtime
 
Forge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User ExperienceForge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User Experience
 
Take Action with Forge Triggers
Take Action with Forge TriggersTake Action with Forge Triggers
Take Action with Forge Triggers
 
Observability and Troubleshooting in Forge
Observability and Troubleshooting in ForgeObservability and Troubleshooting in Forge
Observability and Troubleshooting in Forge
 
Trusted by Default: The Forge Security & Privacy Model
Trusted by Default: The Forge Security & Privacy ModelTrusted by Default: The Forge Security & Privacy Model
Trusted by Default: The Forge Security & Privacy Model
 
Designing Forge UI: A Story of Designing an App UI System
Designing Forge UI: A Story of Designing an App UI SystemDesigning Forge UI: A Story of Designing an App UI System
Designing Forge UI: A Story of Designing an App UI System
 
Forge: Under the Hood
Forge: Under the HoodForge: Under the Hood
Forge: Under the Hood
 
Access to User Activities - Activity Platform APIs
Access to User Activities - Activity Platform APIsAccess to User Activities - Activity Platform APIs
Access to User Activities - Activity Platform APIs
 
Design Your Next App with the Atlassian Vendor Sketch Plugin
Design Your Next App with the Atlassian Vendor Sketch PluginDesign Your Next App with the Atlassian Vendor Sketch Plugin
Design Your Next App with the Atlassian Vendor Sketch Plugin
 
Tear Up Your Roadmap and Get Out of the Building
Tear Up Your Roadmap and Get Out of the BuildingTear Up Your Roadmap and Get Out of the Building
Tear Up Your Roadmap and Get Out of the Building
 
Nailing Measurement: a Framework for Measuring Metrics that Matter
Nailing Measurement: a Framework for Measuring Metrics that MatterNailing Measurement: a Framework for Measuring Metrics that Matter
Nailing Measurement: a Framework for Measuring Metrics that Matter
 
Building Apps With Color Blind Users in Mind
Building Apps With Color Blind Users in MindBuilding Apps With Color Blind Users in Mind
Building Apps With Color Blind Users in Mind
 
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...
Creating Inclusive Experiences: Balancing Personality and Accessibility in UX...
 
Beyond Diversity: A Guide to Building Balanced Teams
Beyond Diversity: A Guide to Building Balanced TeamsBeyond Diversity: A Guide to Building Balanced Teams
Beyond Diversity: A Guide to Building Balanced Teams
 
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed Team
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed TeamThe Road(map) to Las Vegas - The Story of an Emerging Self-Managed Team
The Road(map) to Las Vegas - The Story of an Emerging Self-Managed Team
 
Building Apps With Enterprise in Mind
Building Apps With Enterprise in MindBuilding Apps With Enterprise in Mind
Building Apps With Enterprise in Mind
 

Recently uploaded

Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Recently uploaded (20)

Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff

  • 1. NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Advanced Git Techniques Subtrees, grafting and other fun
  • 2. Get more out of your version control.
  • 3. Today we’ll cover some powerful Git goodies Interactive stagingPainless sub-projects Collating history Interactive commits are an amazing tool at your disposal as you work on complex code changes You can use git subtree to handle external libraries in a clean and efficient way Joining together history of your projects using git replace is useful when migrating to Git
  • 4. git subtree Extract project Alternative to git submodule to handle external dependencies. Inject dependency It allows you to inject an external project into a sub-folder Introduced in 1.7.11 It can be also used to extract a sub-folder as separate project
  • 5. Clean integration pointsStores in regular commitsNo training When and why is git subtree a great choice Does not require your entire team to be trained in the use of the command The command stores the external dependency in regular Git commits. Squashing the history optionally. It makes it easy to see when integrations happened and makes it easy to revert them.
  • 6. Syntax to inject a project Command to inject project git subtree add --prefix target-folder https://bitbucket.org/team/sub.git master --squash Folder where to insert code Repository URL v1.1
  • 7. Under the hood of git subtree commit ab54c4e0b75c3107e3e773ab9b39268abddca002 Author: Nicola Paolucci <npaolucci@atlassian.com> Date: Tue Sep 29 15:27:35 2015 +0200 Squashed ‘src/sub-project‘ content from commit df563ed git-subtree-dir: src/sub-project git-subtree-split: df563ed15fa6…6b2e95d3
  • 8. Result of git subtree add commit 8fb507baf7b270c30c822b27e262d0b44819b4c5 Merge: 606cd3e ab54c4e Author: Nicola Paolucci <npaolucci@atlassian.com> Date: Tue Sep 29 15:27:35 2015 +0200 Merge commit 'ab54c4e0b75c3107e3e773ab9b39268abddca002' as '.vim/bundle/fireplace' commit ab54c4e0b75c3107e3e773ab9b39268abddca002 Author: Nicola Paolucci <npaolucci@atlassian.com> Date: Tue Sep 29 15:27:35 2015 +0200 Squashed '.vim/bundle/fireplace/' content from commit df563ed git-subtree-dir: .vim/bundle/fireplace git-subtree-split: df563ed15fa685ce2508bf16b3ca7e176b2e95d3
  • 9. To keep the sub-project up to date git subtree pull --prefix target-folder https://bitbucket.org/team/sub.git master --squash Command to pull project Folder where to insert code Repository URL v1.5
  • 10. Under the hood of git subtree commit ab54c4e0b75c3107e3e773ab9b39268abddca002 Author: Nicola Paolucci <npaolucci@atlassian.com> Date: Tue Sep 29 15:27:35 2015 +0200 Squashed ‘src/sub-project‘ content from commit df563ed git-subtree-dir: src/sub-project git-subtree-split: df563ed15fa6…6b2e95d3
  • 11. Find the symbolic ref matching a hash (sha-1) sha-1 of last commit pulled Git plumbing to list all remote refs Repository URL git ls-remote https://bitbucket.org/team/sub.git | grep df563ed df563ed15fa685ce2508bf16b3ca7e176b2e95d3 v1.1 5eaff1232acedeca565er7e1333234dacccebfff v1.5 git ls-remote https://bitbucket.org/team/sub.git | grep <sha-1>
  • 12. Aliases to make your life easier! [alias] sba = "!f() { git subtree add --prefix $2 $1 master --squash; }; f" sbu = "!f() { git subtree pull --prefix $2 $1 master --squash; }; f" Alias section of your .gitconfig http://bit.do/git-aliases
  • 13. How to use the aliases git sba <repo URL> <destination-folder> git sba https://bitbucket.org/team/sub.git src/sub
  • 14. When everyone in the team must work on sub-projects When you have constant updates to your dependencies When you have many dependencies When NOT to use git subtree
  • 15. For complex project dependencies Use a dependency tool. Really.
  • 16. Alternatives? Read my rant on project dependencies http://bit.do/git-dep
  • 17. How to extract a project Let’s learn how to use subtree split
  • 18. Git subtree to extract a project Command to split out project git subtree split --prefix my/project/ --branch extracted Folder prefix to extract where we store it
  • 19. Push to new remote We can remove the contents of the folder from the repo Import extracted branch Initialise a new repo and import the extracted branch Remove from old repo After we imported the code we can push it to a new repository git rm -rf my/project git init git pull ../path/ extracted git remote add origin … git push origin -u master
  • 20. Interactive commit Splitting commits semantically in flight!
  • 21. Fine grained control on your commits Knowing this technique frees you from worrying about what to do first Atomic commits make your changes readable Why split changes interactively?
  • 22. We modify a single file (README) in 3 parts # Title Content of my article ## Subtitle second heading Some more paragraph content ## Conclusions
  • 23. We modify a single file in 3 different parts [:~/p/demo] master(+3/-0) ± git diff @@ -1,11 +1,14 @@ # Title Content of my article +Adding a second line to Title. ## Subtitle second heading Some more paragraph content +Adding another line to Subtitle 1 ## Conclusions Here are your conclusions
  • 24. To split those changes in separate commits: git commit --interactive staged unstaged path 1: unchanged +3/-0 README.md *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  • 25. Overview of interactive staging revert The status of the files, whether they are staged or unstaged. update Choose which files to add to the staging area status Undo any action done previously in this session.
  • 26. Overview of interactive staging [2] add untracked Check the unstaged or staged changes in the workspace. patch Add parts of a file to the staging area. This allows you to split commits. diff Add new untracked files to the repository.
  • 27. I finally hit “p” for patch, select the file and ENTER: What now> p staged unstaged path 1: unchanged +3/-0 README.md Patch update>> 1 staged unstaged path * 1: unchanged +3/-0 README.md Patch update>>
  • 28. I finally hit “p” for patch, select the file and ENTER: @@ -1,11 +1,14 @@ # Title Content of my article +Adding a second line to Title. ## Subtitle second heading Some more paragraph content +Adding another line to Subtitle 1 ## Conclusions Here are your conclusions +Adding to the Conclusions. Stage this hunk?!?!
  • 29.
  • 30. A hunk is just a piece of text in a larger file. Diff and patch commands tend to understand changes by clustering them in blocks of continuous text. “ ”
  • 31.
  • 32. If the default hunk size is too big, you can split it: Stage this hunk [y,n,q,a,d,/,s,e,?]? s Split into 3 hunks. @@ -1,7 +1,8 @@ # Title Content of my article +Adding a second line to Title. ## Subtitle second heading Some more paragraph content
  • 33. Let’s stage this hunk, or add it to the staging area: Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y @@ -4,8 +5,9 @@ ## Subtitle second heading Some more paragraph content +Adding another line to Subtitle 1 ## Conclusions Here are your conclusions Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]?
  • 34. Now so skip all the rest pressing “q” twice:
  • 35. The result is a neat new commit and the rest left: 14a0be4 [4 minutes ago] (HEAD -> master) Add content to Title [Nick] git diff diff --git i/README.md w/README.md index fc26295..0ef85c4 100644 --- i/README.md +++ w/README.md @@ -6,7 +6,9 @@ Adding a second line to Title. ## Subtitle second heading Some more paragraph content +Adding another line to Subtitle 1 ## Conclusions
  • 36. When you need help just press “?” Stage this hunk [y,n,q,a,d,/,s,e,?]? ? y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk
  • 38. Cross VCS mergesUnify two reposFast migration from svn Why collate history? Migrate immediately from Subversion, attach the earlier history after the migration. You have two repositories that should actually be only one. You need to perform Subversion merges in a Git branch
  • 39. One relevant example: Linux kernel Today use git replace The entire history of the Linux kernel is split over three different repos. Originally in Grafts Which are local pair of ids connecting a commit id (SHA-1) to the next Linux kernel is split Available in the stock git distribution since version 1.6.5
  • 40. git replace is capable to replace any object with any other object. It tracks these swaps via refs which you can push and pull between repositories. “ ”
  • 41. git replace in practice shallow first last legacy shallow clone with cut history git replace first last
  • 42. First commit of restarted repo git checkout -b shallow origin/shallow git log --max-parents=0 master git tag 56eacf first -m”Tag… commit” shallow first
  • 43. Last commit of legacy repo git checkout -b legacy origin/legacy git rev-parse --verify legacy git tag 84abb last -m”Tag… commit” last legacy
  • 44. git replace in practice shallow first last legacy shallow clone with cut history git replace first last
  • 45. Replacements are persisted cat .git/refs/replace/56eac…7cc 84abb39d9aab234dfba2e41f13f693fa5edbfe22 git push origin ‘refs/replace/*’
  • 46. If you want to make the git replace changes permanent and free the team from pulling those refs, do a final pass using git filter-branch “ ”
  • 47. Go forth and enrich your Git experience
  • 48. Thank you! NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Twitter: @durdn
  • 49. • GIF backdrops taken from giphy.com • Icons from thenounproject.com credits below Image credits