BM: Baca dalam Bahasa Melayu
World 4: Hello GitHub
Force push, safely
You will learn: when a force push is OK, and how --force-with-lease protects your team.
The problem
You pushed “Add about pgae”. Oops! You fixed the message with --amend. Now git push is rejected. git push --force is tempting. What’s the risk?
Pick one answer.
Watch
git push --force replaces GitHub's main with yours. Aisyah's commit and the old typo commit vanish from GitHub.
- e82b02fAdd about page (only on your laptop)main (HEAD is here)
- f91c599Add about pgae (fetched, not in main yet)origin/main
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
- f0f8b99Add Aisyah's day 2 · Aisyah (only on GitHub)main
- f91c599Add about pgae
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
A force push: Make the remote branch match yours, even if that throws away commits there. says: make GitHub’s main exactly like mine. Aisyah pushed after your last fetch. Her commit just vanished.
Try it
Build the safer force push.
Tap the pieces in the right order.
Hint
Look for the one with a lease.Watch
git push --force-with-lease checks GitHub first. GitHub moved since your last fetch, so the push stops and the parcel comes back. Aisyah's commit stays.
- e82b02fAdd about page (only on your laptop)main (HEAD is here)
- f91c599Add about pgae (fetched, not in main yet)origin/main
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
- f0f8b99Add Aisyah's day 2 · Aisyah (only on GitHub)main
- f91c599Add about pgae
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
--force-with-lease checks first. Is GitHub still where my last fetch saw it? Aisyah pushed since, so it stops. Her work stays safe.
Check
Force push: OK, or needs work? Swipe each one.
Swipe right for good, left for needs work. Or use the buttons.
Force push your own branch after you rebase it
Try it
This time nobody pushed since your last fetch. Send your fixed commit safely.
- a26f6d8Add about page (only on your laptop)main (HEAD is here)
- f91c599Add about pgae (fetched, not in main yet)origin/main
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
- f91c599Add about pgaemain
- ea2c020Add purple style
- f6c78e5Add home page
- 2efd0f2Add README
Tap an action. Watch the courier.
You did it!
You can now force push only when it’s safe, with –force-with-lease.
Go deeper (optional)
The lease trusts your origin/main. Some editors fetch quietly in the background, which updates it. Then the lease may pass without you seeing the new commits. --force-if-includes adds one more check for that. Shared mistakes on main? Use git revert instead.
Bahasa Melayu
Anda push “Add about pgae”. Alamak! Anda baiki mesej itu dengan --amend. Kini git push ditolak. git push --force nampak menggoda. Apa risikonya?
Force push (push paksa) paksa GitHub jadi sama tepat dengan main anda. Aisyah push selepas fetch terakhir anda. Commitnya baru sahaja lesap.
Bina force push yang lebih selamat.
--force-with-lease semak dulu. Adakah GitHub masih seperti fetch terakhir saya? Aisyah dah push, jadi ia berhenti. Kerjanya selamat.
Force push: okey, atau perlu dibaiki? Leret setiap satu.
Kali ini tiada siapa push sejak fetch terakhir anda. Hantar commit yang dibaiki dengan selamat.
Kini anda boleh force push hanya bila selamat, dengan –force-with-lease.
You finished this before. Practice is always welcome!
Official docs: git push
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?