هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
If a conflict stops the rebase: fix the file, git add FILE, git rebase --continue. To stop and go back: git rebase --abort.
Step by step
- Commit or stash your work first — rebase needs a clean working tree:
- **Rebase onto the latest
main** (quick answer). Git takes your commits off, moves the branch toorigin/main, and applies them again one by one. - Conflicts — one commit at a time:
تذكّر
during a rebase --ours is main and --theirs is your commit.
- Clean up before review — squash "fix typo" commits into the real ones with an interactive rebase (in your own editor):
pick 1a2b3c4 Add rate limit to login
fixup 5d6e7f8 fix typo
pick 9a8b7c6 Add tests for rate limitOr mark fix commits as you make them and let Git sort them:
- Push the new history — the commits have new IDs, so a normal push is refused.
--force-with-leaseonly overwrites if nobody else pushed to the branch meanwhile (safer than--force):
git push --force-with-lease- The golden rule: rebase only your own branches. Never rebase
mainor a branch others have pulled — their history would no longer match. - **Make
git pullrebase by default** on feature branches:
git config --global pull.rebase trueCheck that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
cannot rebase: You have unstaged changes | Dirty working tree. | Commit or git stash first. |
| The same conflict for every commit | Many commits touch the same lines. | Squash first, or merge main instead; rerere helps. |
rejected … stale info on push | Someone else pushed to your branch. | git fetch, look at their commits, rebase again. |
| You lost commits | A wrong resolution or reset. | git reflog shows the state before the rebase; git reset --hard HEAD@{N}. |
| Teammates have broken history | You rebased a shared branch. | Avoid it; they must reset to the new remote branch. |
| Not sure how to finish | Rebase still in progress. | git status tells you; --continue or --abort. |
Go further
- Command pages: git.
- Next how-tos: Resolve a Git merge conflict, Work with branches and pull requests, Undo the last Git commit.
- Learn it: Git — Rebase, Git — Conflicts in a rebase, Git — Interactive rebase, Git — Rebase or merge?.
1Why use --force-with-lease instead of --force after a rebase?
It refuses to overwrite the remote branch if someone else pushed to it meanwhile.
2Which branches should you never rebase?
Shared ones like main or branches other people already pulled.