Let’s review the dangers we’ve addressed so far. I know, I know, it’s scary stuff - but we have to be mindful or our coworkers might end up hating our guts! If you look back through this lesson you’ll see a common thread. amend, rebase, reset, push --force are all especially dangerous when you’re collaborating with others. These commands can destroy work your coworkers have created. So keep that in mind. When attempting to rewrite history, always check the dangers of the particular command you’re using and follow these best practices for the commands we’ve covered:
- If working on a team project, make sure rewriting history is safe to do and others know you’re doing it.
- Ideally, stick to using these commands only on branches that you’re working with by yourself.
- Using the
-fflag to force something should scare you, and you better have a really good reason for using it. - Don’t push after every single commit, changing published history should be avoided when possible.
- Regarding the specific commands we’ve covered:
- For
git amendnever amend commits that have been pushed to remote repositories. - For
git rebasenever rebase a repository that others may work off of. - For
git resetnever reset commits that have been pushed to remote repositories. - For
git push --forceonly use it when appropriate, use it with caution, and preferably default to usinggit push --force-with-lease.
- For
rebase squash git checkout -b branchname
https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet