Understanding Git in a Simple Way - Part 6

Published: (December 27, 2025 at 03:22 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

When working on a feature branch

You may need to incorporate the latest changes from main. Rebasing lets you “replay” your branch’s commits on top of the updated main, resulting in a clean, linear history.

Create and switch to a new branch

git checkout -b new-feature

Make some commits

git add .
git commit -m "D"

Update the main branch

git checkout main
git pull origin main

Perform a rebase

git rebase main

Git takes the commits from your feature branch and re‑applies them onto the tip of main. After the rebase, the original commits become orphaned, and your branch has a linear history that includes the latest changes from main.

Handling conflicts

If conflicts arise during the rebase:

  1. Resolve the conflicts in the affected files.

  2. Stage the resolved files:

    git add 
  3. Continue the rebase:

    git rebase --continue

You can abort the rebase at any time to return to the pre‑rebase state:

git rebase --abort

Git commands reference

CommandDescription
git checkout -bCreates and switches to a new branch.
git rebase mainMoves your current branch’s commits to the tip of main.
git rebase --continueContinues the rebase after resolving conflicts.
git rebase --abortStops the rebase and restores the branch to its original state.
Back to Blog

Related posts

Read more »

Understanding Git in Simple way - Part 2

Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a a single platform for all development tools, cheat codes, and TL;DRs — a free, open‑...