Git MERGE vs REBASE: The Definitive Guide

53,856
0
Published 2023-08-29
The better way to learn Git with live coding and motion graphics:
learngit.io/

Newsletter readers get my videos early: newsletter.themoderncoder.com/

----

This is the definitive tutorial for git rebase and git merge. We'll cover everything you'll need to know about how to use rebase and merge to streamline your version control workflow. Start by understanding the fundamentals of git merge: we'll cover 3-way merges, fast-forward merges and more. Then we'll then cover best practices for using git rebase in collaborative situations with other developers, and review common rebase pitfalls to avoid. We'll also explore some pro git rebase and merge workflow tips to help you master the most common git workflow.

CHAPTERS
0:00 Intro
0:18 Merging: 3-way merge
3:00 Merging: Fast-forward merge
4:47 Rebase
6:02 Merge & Rebase Workflow
6:41 Rebase Pitfalls

MY TECH
www.themoderncoder.com/wfh-nyc-desk-tour-2022/

MUSIC
Music from Uppbeat (free for Creators!):
uppbeat.io/t/danijel-zambo/stardust
License code: 0Y2YDUPOMXGYYQML

#git #rebase #merge #github #learngit #gitmerge #gitrebase #development #softwareengineering #programming #coding #versioncontrol #developer #technology #tutorial #stepbystepguide #gitrepository #vcs #programmingtips #codersofinstagram #codingcommunity #learnprogramming #softwaredevelopment #codingtutorial #gitexplained

All Comments (21)
  • @celikvolkan
    Best explanation I have ever seen on YouTube about merge vs rebase. Thank you for sharing.😺
  • Thanks a lot! At last after several years using Git, I (think) I finally grasped it.
  • @rpf23543
    Probably the best videos about git, out there. The animations are a huge help. Thank you so much!
  • @matk2283
    Amazing tutorial !! really appreciate posting this tutorial explaining "git merge" and "git rebase"
  • @johndibling8091
    Great video. I've been using Git forever, and this is probably the best explanation I've ever seen of merge, rebase and fast-forward.
  • @nanonkay5669
    I'd like to think of both as merging, but done differently. Here's how: "Git merge" from a current branch into the target branch is when Git takes the latest changes of the current branch, then take the latest changes of the target branch and combine them. The new combination is made into a new commit and placed as the latest commit of the target branch. Git will still keep around the history of all the commits that had been made up until the merge of either branch. "Git Rebase" from current branch into target branch is when Git first takes all the commits from the current branch, lines them up in the order they were made and puts them aside for now. Then Git takes the oldest commit from current branch and "merges" it with the latest commit on the target branch by doing it like a regular merge: combing the changes, make a new commit that represents those combined changes then places that new commit as the latest commit on the target branch. Then Git moves on the second oldest commit on the current branch and repeats the process. All the way until the latest commit of the current branch is merged. But remember, the current branch is still set aside, what will Git do with those commits that have effectively become duplicates? Git will just delete those commits, hence why history has been rewritten. Hope this helps
  • @ariyaneghbal
    Your videos are the most clear I ever seen on this topic and still contains enough details
  • @yashpandey9550
    Hey man, amazing video with great illustrative animations out there. There's just one thing which I found confusing. So in most of the scenarios that I have worked in, the git workflow looks something like this: 1) Create a feature_branch from main: `git checkout -b feature_branch`. 2) Makes changes to your feature branch: `git add -A && git commit -m "Your commit message"`. 3) During the development process some changes were pushed and merged to the REMOTE main branch. So you need to sync your LOCAL main with the REMOTE main: `git checkout main && git pull origin main` Once that's done... 4) You checkout your feature_branch and merge the updated local main with your feature_branch: `git checkout feature_branch && git merge main` 5) You push your local feature_branch to remote and create a pull request: `git push origin feature_branch` In this workflow we can probably replace the merge thing in step 4 with a rebase thing, if this feature branch is being worked on by a single contributor. What confuses me in the video is that at 5:40 : when we are on the feature branch we run `git rebase main` and then we checkout to main and run `git merge feature_branch`. Maybe that's done to illustrate fast forwarding merge here but in a production workflow isn't it discouraged to merge directly onto the main branch? Let me know if I missed a point or something.
  • @ogreeni
    Great video! You seriously deserve more recognition.
  • @robwalker4653
    I quite like a semi linear approach. If I have a release/feature branch that multiple people are working on, rebase to keep in linear. Then when then when you want to merge to master, do a rebase and then merge with no fast forward. This way if you use gitversion, your main branch only has one commit per release but you have full history of commits for each release without a bird nest.
  • @erdemkosk
    This is the best git videos on youtube. This is amazing work. I am begging to you please move whole git with kind of videos
  • @MarkW2711
    Excellent video, I've always been worried about using rebase, this helps massively
  • @niravpatel1239
    First time i have seen such an attractive videos regarding git, captivating !!