August 19, 2026

GIT Rebase

1. Check out your main branch:

$ git checkout main

Reference: https://docs.gitlab.com/topics/git/git_rebase/

2. "Ensure you have the latest contents of the target branch. In this example, the target branch is main:"

git fetch origin main

3. "Check out your branch:"

git checkout my-branch

4. "Rebase against the main branch:"

git rebase origin/main

5. "Resolve the conflicts in your editor."

6. "Stage the changes:"

git add .

7. "Continue the rebase:"

git rebase --continue

8. "Force push your changes to the target branch, while protecting others’ commits:"

git push origin my-branch --force-with-lease