Git Rebase

إعادة التأسيس في Git (Rebase)

Advancedgit1 min read
rebasegit rebaseinteractive rebaserebase -isquash commits

Definition

A Git operation that moves or replays a branch's commits on top of another branch for a linear history.

عملية Git تُحرّك أو تُعيد تشغيل commits فرع على فرع آخر للحصول على تاريخ خطي.

Why It Matters

Rebase is used to clean up sprint branches before merging to master — squashing 15 'WIP' commits into 3 clean meaningful commits improves the project's git history.

يُستخدم Rebase لتنظيف فروع السبرينت قبل الدمج إلى master — تسطيح 15 commit 'WIP' إلى 3 commits نظيفة وذات معنى يُحسّن تاريخ git المشروع.

Full Definition

Rebase re-applies commits from one branch on top of another, creating new commit SHAs. Unlike merge (which preserves branch history), rebase creates a linear history as if the branch work happened after the target branch. Interactive rebase (`git rebase -i`) lets you squash, edit, reorder, or drop commits before merging. Never rebase shared/public branches — it rewrites history others depend on.
Rebase يُعيد تطبيق commits من فرع على آخر، مُنشئًا تجزئات SHA جديدة. على عكس الدمج (الذي يحفظ تاريخ الفرع)، يُنشئ rebase تاريخًا خطيًا. لا تُعِد تأسيس الفروع المشتركة/العامة أبدًا.

Example Usage

git rebase main feature-branch — replay feature-branch commits on top of latest main

git rebase main feature-branch — إعادة تشغيل commits feature-branch على أحدث main

Knowledge Graph

Avoid these mistakes when using Git Rebase:

1

Rebasing public branches others have pulled — causes divergent histories and confuses collaborators

2

Not understanding that rebase creates new commits with different SHAs

Sign in to unlock guided AI explanations from AI Teacher.

Generate a Prompt

Copy this prompt and use it directly with any AI model — no setup needed.

Ready-to-Use Prompt
Help me build a project using Git Rebase.

Explain:
1. What is Git Rebase and why it matters
2. The core architecture and required tools
3. Step-by-step implementation plan
4. Common mistakes to avoid: Rebasing public branches others have pulled — causes divergent histories and confuses collaborators, Not understanding that rebase creates new commits with different SHAs
5. Best practices and production tips

Official Resources