Pushing Changes
git push transfers local commits to a remote repository and updates remote references when permitted. Modern hosting platforms may reject pushes because of branch protection, authentication requirements, or non-fast-forward history.
A push does not normally send every object in your entire repository; Git transfers the objects required to update the remote.
Prefer --force-with-lease
When a history rewrite is genuinely required, prefer --force-with-lease because it helps avoid overwriting remote work that you have not seen.
Push a Branch
git push -u origin feature/login
git push
git push --force-with-lease💡 The first push establishes tracking. A normal push sends new commits.
--force-with-lease is a safer history-rewrite mechanism than unconditional --force because it checks the expected remote state.Key Takeaways
- Push transfers commits and updates remote references.
- Protected branches can reject direct pushes.
--force-with-leaseis safer than blind--force.
Knowledge Check
Why is `--force-with-lease` generally safer than `--force`?