SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Git Rebase vs Merge
a deep dive into the mysteries of revision control
Merge
Merge
a new commit on top of both branches that
should be merged - known as merge commit
Merge
You work on feature_branch
Merge
Before pushing you update your branch with master’s
changes - git pull origin master
Merge
git pull = git fetch + git merge
git fetch - copies origin master into origin/master
git merge - merges origin/master into master
Merge history graph
Merge - Pros & Cons
Pros:
● Simple to use and understand.
● Keeps information about the historical existence of branches.
● Existing commits on the source branch are unchanged and remain valid.
Cons:
● History can become intensively polluted by lots of merge commits.
● Visual charts of your repository can have non-informative branch lines.
Rebase
a different approach
Rebase
a way to cut of a set of commits from a branch
and apply those commits on another branch
Rebase
Let’s get back to our previous example:
Rebase
What does rebase do: It cuts off these commits
The commits don’t have any information about their parents
anymore.
Rebase
The system then applies them on top of the new branch.
We literally cut of these commits and then apply it on top of
the new branch.
Rebase
Why does merge even exists if we found such a nice way
to handle our history?
Our commit IDs changed!
Why?
Rebase
...because we have a new parent.
Git thinks of our commits as patches and applies them on
top of the new branch.
Therefore Git processes our commits as new commits.
And again, NEW COMMITS!
Rebase
git rebase [branch]
Rebase - Golden Rule
● Never rebase commits that you have pushed
to a public repository. Only rebase local
branches.
Why?
Rebase - Golden Rule
● When you rebase pushed branch, you’re
abandoning existing commits and creating
new ones that are similar but different.
So you will rewrite the history...
Rebase history graph
Rebase - Pros & Cons
Pros:
● Clean and flat history.
● Concise commits covering a logical change (can squash series of commits
into one)
● Reduction of merge commits
● Manipulating single commit is easy (e.g. reverting a commit)
Cons:
● More complex
● Rebasing can be dangerous! Can cause history rewrite if done incorrectly
The key of having a clean history
… is to have a “fast forward” effect
Fast Forward
Rebase - Best Practice
$ git checkout -b security_hole_fix
...fix...fix...fix
$ git commit
$ git rebase master
$ git checkout master
$ git merge security_hole_fix
then you get fast-forward effect
Who uses what?
Merge
➔ Atlassian (with GitHub pull requests for code reviews)
➔ Git
Rebase
➔ Guava
Rebase
If you are not sure you fully understand rebase
-
Don’t do it…
BUT
If you like it, try out !!!

Contenu connexe

Tendances

Tendances (20)

The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Github
GithubGithub
Github
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git and GitFlow branching model
Git and GitFlow branching modelGit and GitFlow branching model
Git and GitFlow branching model
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git flow Introduction
Git flow IntroductionGit flow Introduction
Git flow Introduction
 
Git basics
Git basicsGit basics
Git basics
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git Branching for Agile Teams
Git Branching for Agile Teams Git Branching for Agile Teams
Git Branching for Agile Teams
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
 

En vedette

Conflicting Advice on Git Usage Patterns & Their Implications
Conflicting Advice on Git Usage Patterns & Their ImplicationsConflicting Advice on Git Usage Patterns & Their Implications
Conflicting Advice on Git Usage Patterns & Their Implications
YoungSeok Yoon
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
MongoSF
 

En vedette (11)

Git rebase explained
Git rebase explainedGit rebase explained
Git rebase explained
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Sendo um GIT master
Sendo um GIT masterSendo um GIT master
Sendo um GIT master
 
Conflicting Advice on Git Usage Patterns & Their Implications
Conflicting Advice on Git Usage Patterns & Their ImplicationsConflicting Advice on Git Usage Patterns & Their Implications
Conflicting Advice on Git Usage Patterns & Their Implications
 
Minicurso Git
Minicurso GitMinicurso Git
Minicurso Git
 
Verzovani kodu s Gitem (Karel Minarik)
Verzovani kodu s Gitem (Karel Minarik)Verzovani kodu s Gitem (Karel Minarik)
Verzovani kodu s Gitem (Karel Minarik)
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositories
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 

Similaire à Git Rebase vs Merge

Git rewriting git history
Git   rewriting git  historyGit   rewriting git  history
Git rewriting git history
LearningTech
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
Gerrit Wanderer
 

Similaire à Git Rebase vs Merge (20)

Git tips
Git tipsGit tips
Git tips
 
Git rewriting git history
Git   rewriting git  historyGit   rewriting git  history
Git rewriting git history
 
Working with others using git and Github
Working with others using git and GithubWorking with others using git and Github
Working with others using git and Github
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
Advanced Git - Functionality and Features
Advanced Git - Functionality and FeaturesAdvanced Git - Functionality and Features
Advanced Git - Functionality and Features
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
 
MakingGitWorkForYou
MakingGitWorkForYouMakingGitWorkForYou
MakingGitWorkForYou
 
Git slides
Git slidesGit slides
Git slides
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Git Best Practices.pptx
Git Best Practices.pptxGit Best Practices.pptx
Git Best Practices.pptx
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawan
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
[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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 

Git Rebase vs Merge

  • 1. Git Rebase vs Merge a deep dive into the mysteries of revision control
  • 3. Merge a new commit on top of both branches that should be merged - known as merge commit
  • 4. Merge You work on feature_branch
  • 5. Merge Before pushing you update your branch with master’s changes - git pull origin master
  • 6. Merge git pull = git fetch + git merge git fetch - copies origin master into origin/master git merge - merges origin/master into master
  • 8. Merge - Pros & Cons Pros: ● Simple to use and understand. ● Keeps information about the historical existence of branches. ● Existing commits on the source branch are unchanged and remain valid. Cons: ● History can become intensively polluted by lots of merge commits. ● Visual charts of your repository can have non-informative branch lines.
  • 10. Rebase a way to cut of a set of commits from a branch and apply those commits on another branch
  • 11. Rebase Let’s get back to our previous example:
  • 12. Rebase What does rebase do: It cuts off these commits The commits don’t have any information about their parents anymore.
  • 13. Rebase The system then applies them on top of the new branch. We literally cut of these commits and then apply it on top of the new branch.
  • 14. Rebase Why does merge even exists if we found such a nice way to handle our history? Our commit IDs changed! Why?
  • 15. Rebase ...because we have a new parent. Git thinks of our commits as patches and applies them on top of the new branch. Therefore Git processes our commits as new commits. And again, NEW COMMITS!
  • 17. Rebase - Golden Rule ● Never rebase commits that you have pushed to a public repository. Only rebase local branches. Why?
  • 18. Rebase - Golden Rule ● When you rebase pushed branch, you’re abandoning existing commits and creating new ones that are similar but different. So you will rewrite the history...
  • 20. Rebase - Pros & Cons Pros: ● Clean and flat history. ● Concise commits covering a logical change (can squash series of commits into one) ● Reduction of merge commits ● Manipulating single commit is easy (e.g. reverting a commit) Cons: ● More complex ● Rebasing can be dangerous! Can cause history rewrite if done incorrectly
  • 21. The key of having a clean history … is to have a “fast forward” effect
  • 23. Rebase - Best Practice $ git checkout -b security_hole_fix ...fix...fix...fix $ git commit $ git rebase master $ git checkout master $ git merge security_hole_fix then you get fast-forward effect
  • 24. Who uses what? Merge ➔ Atlassian (with GitHub pull requests for code reviews) ➔ Git Rebase ➔ Guava
  • 25. Rebase If you are not sure you fully understand rebase - Don’t do it… BUT
  • 26. If you like it, try out !!!