MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Rebasing Branches: Linear History with git rebase vs git merge0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
7.1Shelving Changes Temporarily with git stash (save, pop, apply, drop)7.2Undoing Changes Safely: git restore, git reset, and git revert7.3Rebasing Branches: Linear History with git rebase vs git merge7.4Tagging Milestones and Software Releases with git tag
HomeTutorialsGit & GitHub BasicsRebasing Branches: Linear History with git rebase vs git merge
Tagging Milestones and Software Releases with git tag

Rebasing Branches: Linear History with git rebase vs git merge

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

In team development, branches inevitably diverge. While git merge combines branches by generating a two-parent merge commit, Git provides an alternative approach called git rebase. Rebasing rewrites history to create a clean, completely linear commit timeline.


1. The Core Concept: Re-basing Your Commits

Consider two diverging branches:

1Base Branch (main): (C1) ---> (C2) -------------> (C3) ---> (C4) [main]
2 \
3Feature Branch: (C5) ---> (C6) [feature-search]

If You Use git merge:

Merging creates a merge commit tying C4 and C6 together, preserving the branching knot.

If You Use git rebase:

"Rebase" literally means: take the base of my branch and change it to a new base commit! Git:

  1. 1
    Temporarily shelves commits C5 and C6 as diff patches.
  2. 2
    Fast-forwards feature-search to the tip of main (C4).
  3. 3
    Re-applies the patches C5 and C6 one by one on top of C4 as brand new commits (C5' and C6' with new hashes!).
1After `git rebase main`:
2(C1) ---> (C2) ---> (C3) ---> (C4) [main] ---> (C5') ---> (C6') [feature-search]

The resulting history is completely flat and linear, as if you started developing your feature today!


2. How to Rebase in Practice

1# 1. Switch to the feature branch you want to rebase
2git switch feature-search
3 
4# 2. Rebase onto main
5git rebase main

Resolving Conflicts During Rebase:

If a conflict occurs while applying C5':

  1. 1
    Git halts and displays the conflict markers in the file.
  2. 2
    Edit the file, remove the conflict markers, and stage: git add <file>.
  3. 3
    > [!IMPORTANT]

Do NOT run git commit! Instead, continue the rebase:

1 git rebase --continue
  1. 1
    If you want to abort the rebase and return to where you started:
1 git rebase --abort

3. Interactive Rebasing: Polishing Commits (git rebase -i)

Before submitting a Pull Request, you might have several messy commits:

  • "wip"
  • "fixed typo"
  • "forgot semicolon"
  • "actual feature"

Interactive rebase lets you clean, reorder, and squash them into professional commits:

1# Interactively rebase the last 4 commits
2git rebase -i HEAD~4

Git opens an editor showing:

1pick 3a89e12 feat: add search input component
2pick 4b91e23 wip: test debounce
3pick 7c10d34 fix typo in search handler
4pick 9f20e45 style: align search dropdown

Common Interactive Commands:

  • pick: Keep the commit as is.
  • reword: Keep the commit, but edit the commit message.
  • edit: Pause to amend files within this commit.
  • squash (or s): Melds this commit into the previous commit, combining messages!
  • drop (or d): Completely deletes the commit!

4. The Golden Rule of Rebasing

Important Warning
[!CAUTION] The Golden Rule of Rebase: Never rebase a branch that has been pushed to a public, shared repository (like main)! Rebasing changes commit hashes. If teammates have branched off those commits, rebasing creates duplicate conflicting histories that cause chaos. Only rebase your own private local feature branches.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary visual difference between a history merged with git merge vs git rebase?
Question 2
What happens to the commit hashes of commits that are rebased?
Question 3
During an active rebase with conflicts, after resolving conflict markers and staging files, what command should you run?
Question 4
What does the squash (or s) command do inside an interactive rebase (git rebase -i)?
Question 5
Why must developers never rebase public shared branches like main?
Next Lesson

Tagging Milestones and Software Releases with git tag

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Undoing Changes Safely: git restore, git reset, and git revertTagging Milestones and Software Releases with git tag

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext