Files
Advanced-Git/contents/how-to-use-git-push-force-with-lease-safely.md
2025-07-26 07:49:48 +00:00

1.4 KiB

⬅️ Back to Table of Contents

How to Use git push --force-with-lease Safely

Category: Collaboration

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

  1. Fetch the latest changes: git fetch origin
  2. Push with lease: git push --force-with-lease
  3. If rejected, pull and rebase: git pull --rebase origin main
  4. Resolve conflicts, commit, and retry push

Prerequisites

  • You must have permission to push to the branch.

Warnings

  • ⚠️ Never use --force unless you are sure. Prefer --force-with-lease.

➡️ Continue to Next Topic: Past commits of a specific file


Author: mike-rambil • Updated: 2024-06-10 • Tags: push, force, safe