SlideShare a Scribd company logo
1 of 21
Download to read offline
Git Workshop
Discussion items
• How to merge
• Branches with one commit
• Reverts
How to merge
How to merge
• It’s simple!
1. Make sure the source and destination branch are
up to date
2. Merge and solve conflicts
3. Run all the tests
4. Push to remote repository
How to merge
1. Make sure the source and destination branch are up
to date
; deal with the source_branch
•
•

git checkout source_branch
git pull --rebase origin source_branch

; deal with the destination_branch
•
git checkout destination_branch
•
git pull --rebase origin destination_branch
; sometimes the branches are not updated so we (always) need to:
•
git fetch
How to merge
2. Merge and solve conflicts
•

git merge --no-ff source_branch

•

Optional (only if you have conflicts):
–
–
–

git mergetool –y
git add -A <all the files that had a conflict>
git commit -sv
How to merge
3. Run all the tests
•
•

gradlew --offline clean check
gradlew --offline clean runPdiTests

•

If tests fail: FIX THEM before you continue!
How to merge
4. Push to remote repository
•

git push origin destination_branch
How to merge
Stuff that can go wrong

someone might have pushed something while
you were doing the merge
How to merge
How to deal with this
• Simple solution: before a merge tell the team
not to put anything on the destination branch

• Not so simple: reset everything and start again
– git checkout destination_branch
– git reset --hard origin/destination_branch
– start over (update the branches, etc)
Branches with one commit
Branches with one commit
• NO!
If you have a single commit do NOT create a
new branch.
If you do create a new branch you should use:
git merge source_branch
instead of
git merge --no-ff source_branch
Branches with one commit

Simple rule
–
–

1 commit --> no branch
> 1 commit --> create branch
Branches with one commit
Bad vs. good enough
Reverts
Reverts
Reverting the last LOCAL commit:
git reset --hard HEAD~
Or
git reset --hard <commit hash>
Reverts
Reverting any PUSHED commit:
git revert <commit hash>
Reverts
Reverting more than 1 PUSHED commit:
git revert
git revert
git rebase
; reword +

<commit1 hash>
<commit2 hash>
–i HEAD~2
fixup/squash
Reverts
Reverting more than 1 PUSHED commit:
Example:
Reverts
Reverting a LOCAL merge:
git reset --hard ORIG_HEAD
Reverts
Reverting a PUSHED merge:
git checkout <branch with merge>
git revert -m 1 <merge commit hash>

More Related Content

What's hot

Git workflows
Git workflowsGit workflows
Git workflows
Xpand IT
 
40 square's git workflow
40 square's git workflow40 square's git workflow
40 square's git workflow
Ruben Tan
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model
abodeltae
 

What's hot (19)

Collaborative development with git
Collaborative development with gitCollaborative development with git
Collaborative development with git
 
Git censored.key
Git censored.keyGit censored.key
Git censored.key
 
Git workflows
Git workflowsGit workflows
Git workflows
 
Git and GitHub crash course
Git and GitHub crash courseGit and GitHub crash course
Git and GitHub crash course
 
Git
GitGit
Git
 
Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014
 
Git locally git rm/revert/reset
Git locally git rm/revert/resetGit locally git rm/revert/reset
Git locally git rm/revert/reset
 
Git
GitGit
Git
 
Introduction to GitHub
Introduction to GitHubIntroduction to GitHub
Introduction to GitHub
 
40 square's git workflow
40 square's git workflow40 square's git workflow
40 square's git workflow
 
Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1
 
Git Rebase - An alternative to merge
Git Rebase - An alternative to mergeGit Rebase - An alternative to merge
Git Rebase - An alternative to merge
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model
 
Git presentation
Git presentationGit presentation
Git presentation
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Git branching-model
Git branching-modelGit branching-model
Git branching-model
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
A Git Workflow Model or Branching Strategy
A Git Workflow Model or Branching StrategyA Git Workflow Model or Branching Strategy
A Git Workflow Model or Branching Strategy
 

Viewers also liked (13)

Ejercicios practicos-Ananume
Ejercicios practicos-AnanumeEjercicios practicos-Ananume
Ejercicios practicos-Ananume
 
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
 
Porcu Salvatore
Porcu SalvatorePorcu Salvatore
Porcu Salvatore
 
Welcome to pennsylvania
Welcome to pennsylvaniaWelcome to pennsylvania
Welcome to pennsylvania
 
Odds of investing in indian equity market
Odds of investing in indian equity marketOdds of investing in indian equity market
Odds of investing in indian equity market
 
Naked Colours - A Story of Hope
Naked Colours - A Story of HopeNaked Colours - A Story of Hope
Naked Colours - A Story of Hope
 
Gradle - small introduction
Gradle - small introductionGradle - small introduction
Gradle - small introduction
 
Welcome to pennsylvania
Welcome to pennsylvaniaWelcome to pennsylvania
Welcome to pennsylvania
 
Ppt pak jum (edited)
Ppt pak jum (edited)Ppt pak jum (edited)
Ppt pak jum (edited)
 
'Psyche Art' by Swapnil - Find your Naked Colours
'Psyche Art' by Swapnil - Find your Naked Colours'Psyche Art' by Swapnil - Find your Naked Colours
'Psyche Art' by Swapnil - Find your Naked Colours
 
Tarea de Transformada de Laplace
Tarea de Transformada de LaplaceTarea de Transformada de Laplace
Tarea de Transformada de Laplace
 
Code Retreat
Code RetreatCode Retreat
Code Retreat
 
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
IMPACT GENERAL MAINTENANCE AND CLEANING PVT.LTD.
 

Similar to Git workshop

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

Similar to Git workshop (20)

Working with Git
Working with GitWorking with Git
Working with Git
 
Git basics, Team Workflows (Ciro Miranda)
Git basics, Team Workflows (Ciro Miranda)Git basics, Team Workflows (Ciro Miranda)
Git basics, Team Workflows (Ciro Miranda)
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Managing releases effectively through git
Managing releases effectively through gitManaging releases effectively through git
Managing releases effectively through git
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
Gitflow
GitflowGitflow
Gitflow
 
Git Introduction with illustrations
Git Introduction with illustrationsGit Introduction with illustrations
Git Introduction with illustrations
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
 
Gitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for GitGitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for Git
 
Gitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for GitGitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for Git
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git training
Git trainingGit training
Git training
 
Github
GithubGithub
Github
 
How to make friends with git
How to make friends with gitHow to make friends with git
How to make friends with git
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Git workshop

  • 2. Discussion items • How to merge • Branches with one commit • Reverts
  • 4. How to merge • It’s simple! 1. Make sure the source and destination branch are up to date 2. Merge and solve conflicts 3. Run all the tests 4. Push to remote repository
  • 5. How to merge 1. Make sure the source and destination branch are up to date ; deal with the source_branch • • git checkout source_branch git pull --rebase origin source_branch ; deal with the destination_branch • git checkout destination_branch • git pull --rebase origin destination_branch ; sometimes the branches are not updated so we (always) need to: • git fetch
  • 6. How to merge 2. Merge and solve conflicts • git merge --no-ff source_branch • Optional (only if you have conflicts): – – – git mergetool –y git add -A <all the files that had a conflict> git commit -sv
  • 7. How to merge 3. Run all the tests • • gradlew --offline clean check gradlew --offline clean runPdiTests • If tests fail: FIX THEM before you continue!
  • 8. How to merge 4. Push to remote repository • git push origin destination_branch
  • 9. How to merge Stuff that can go wrong someone might have pushed something while you were doing the merge
  • 10. How to merge How to deal with this • Simple solution: before a merge tell the team not to put anything on the destination branch • Not so simple: reset everything and start again – git checkout destination_branch – git reset --hard origin/destination_branch – start over (update the branches, etc)
  • 12. Branches with one commit • NO! If you have a single commit do NOT create a new branch. If you do create a new branch you should use: git merge source_branch instead of git merge --no-ff source_branch
  • 13. Branches with one commit Simple rule – – 1 commit --> no branch > 1 commit --> create branch
  • 14. Branches with one commit Bad vs. good enough
  • 16. Reverts Reverting the last LOCAL commit: git reset --hard HEAD~ Or git reset --hard <commit hash>
  • 17. Reverts Reverting any PUSHED commit: git revert <commit hash>
  • 18. Reverts Reverting more than 1 PUSHED commit: git revert git revert git rebase ; reword + <commit1 hash> <commit2 hash> –i HEAD~2 fixup/squash
  • 19. Reverts Reverting more than 1 PUSHED commit: Example:
  • 20. Reverts Reverting a LOCAL merge: git reset --hard ORIG_HEAD
  • 21. Reverts Reverting a PUSHED merge: git checkout <branch with merge> git revert -m 1 <merge commit hash>