gitpractice.dev

brewly — Ch.6 · Push a rebased branch

Exercise 6 of 8

Before you start

After rebasing a pushed branch

The server still has your old commits, so a plain push is rejected. You have to replace them.

git push --force-with-lease replaces the branch only if the server still has what you last saw. If a colleague pushed in the meantime, it refuses.

Plain --force overwrites without looking. Avoid it, and never force push a shared branch such as main.

git rebase main
replay your branch on the new main
git push
try it, and read the rejection
git push --force-with-lease
replace your branch on the server
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path