To avoid amending public commits, you can follow these best practices:
-
Use Feature Branches: Always create a new branch for your features or fixes. This keeps your work isolated until it's ready to be merged into the main branch.
git checkout -b feature/my-feature -
Commit Locally First: Make your commits locally and only push them to the remote repository when you're sure they are final.
git commit -m "My commit message" git push origin feature/my-feature -
Review Before Pushing: Use
git logto review your commit history before pushing. This helps ensure that you are satisfied with your commits.git log -
Use Pull Requests: If you're working in a collaborative environment, use pull requests to review changes before merging them into the main branch. This allows for discussion and approval without altering the commit history.
-
Avoid Force Push: When pushing changes, avoid using
--forceunless absolutely necessary. This prevents overwriting commits that others may have pulled.
By following these practices, you can minimize the risk of amending public commits and maintain a clean commit history.
