Search code examples
gitsquash

git squash commits which has been merged locally?


I worked on branch_A and merged it to branch_B (both are local branches)

  1. Is it a good practice to squash commits in branch_A.
  2. What if I'm going to push branch_A to public repo and my master will fetch it in the future?

Solution

  • Squashing is almost never a good idea. First of all, it is rewriting your history, so if you pushed (published) your changes, you should not squash. Then, squashing is removing logical sequence of your work - it makes more difficult to track why you yourself did one change or another.

    Just about the only situation when squashing might be helpful is when you commit without pushing very often (like 20 times a day), but then after few days you have developed new shiny feature and would like to create just one commit that has this feature implemented and publish just that one commit or send it for code review.