0
0
Gitdevops~30 mins

Why rebasing creates linear history in Git - See It in Action

Choose your learning style9 modes available
Why Rebasing Creates Linear History
📖 Scenario: You are working on a project with a friend. Both of you make changes in separate branches. You want to combine your changes in a clean way so the history looks simple and easy to follow.
🎯 Goal: Learn how to use git rebase to create a linear commit history instead of a branching one.
📋 What You'll Learn
Create a new branch called feature from main
Make two commits on feature branch
Switch back to main and make one commit
Use git rebase main on feature branch to apply changes linearly
Show the commit history with git log --oneline --graph
💡 Why This Matters
🌍 Real World
Developers often work on features in separate branches. Rebasing helps keep the project history clean and linear, making it easier to understand what changes were made and when.
💼 Career
Understanding rebasing is important for collaboration in teams using Git. It helps avoid messy histories and simplifies code reviews and debugging.
Progress0 / 4 steps
1
Create initial branches and commits
Create a new branch called feature from main. Then make two commits on feature branch with commit messages feat: add first feature and feat: add second feature. Use touch and git add to create files feature1.txt and feature2.txt respectively.
Git
Need a hint?

Use git checkout -b feature to create and switch to the feature branch.

Use touch to create files and git add to stage them before committing.

2
Make a commit on main branch
Switch back to main branch. Create a file called hotfix.txt and commit it with the message fix: hotfix on main.
Git
Need a hint?

Use git checkout main to switch back to main branch.

Create the file and commit it as before.

3
Rebase feature branch onto main
Switch back to feature branch. Use git rebase main to move the feature branch commits on top of the latest main branch commit.
Git
Need a hint?

Use git checkout feature to switch to feature branch.

Then run git rebase main to replay feature commits on top of main.

4
Show the linear commit history
Run git log --oneline --graph to display the commit history. Notice how the commits from feature branch appear in a straight line after the main branch commit.
Git
Need a hint?

Use git log --oneline --graph to see the commit history as a graph.

You should see a straight line of commits after rebasing.