mirror of
https://github.com/mike-rambil/Advanced-Git.git
synced 2025-12-26 20:21:40 -06:00
1.4 KiB
1.4 KiB
How to Use git push --force-with-lease Safely
Safely force-push to a branch without overwriting others' work.
Guide to using git push --force-with-lease to avoid overwriting others' work when force-pushing.
Command
git push --force-with-lease
Examples
- Safely force-push your changes.
git push --force-with-lease
- Force-push a specific branch with lease protection.
git push --force-with-lease origin feature-branch
Steps
- Fetch the latest changes:
git fetch origin - Push with lease:
git push --force-with-lease - If rejected, pull and rebase:
git pull --rebase origin main - Resolve conflicts, commit, and retry push
Prerequisites
- You must have permission to push to the branch.
Warnings
- ⚠️ Never use
--forceunless you are sure. Prefer--force-with-lease.
Links
➡️ Continue to Next Topic: Past commits of a specific file
Author: mike-rambil • Updated: 2024-06-10 • Tags: push, force, safe