No matter what Git branching strategy you are using, you’ll still open a pull request (PR) for peer review. No one is perfect and anyone hardly remembers their code after few weeks😬
Once PR is reviewed and approved, you would merge it to the destination branch. But, at this point when we're merging the PR, we can decide whether to use "Merge pull request" or "Squash and merge". Any of these options will ultimately merge the code into the destination branch, however, we can control how commit history is propagated to the destination branch.
The recommendation is to choose the "Squash and merge" option, as it just creates one single commit in the destination branch, hiding all the commits coming from the source branch i.e. as the name says, it squashes all commits into one commit.
And yet we have the option to see commits that came from the source by traversing through the newly created commit. In other words, by clicking on the PR number that was merged e.g. #1 in the above screenshot. This helps to keep the destination/main branch's commit history neat and tidy.
Whereas, if we choose the "Merge pull request" option, all commits along with a new commit for the PR will be created in the destination branch. And that looks like finding commit in a haystack.
But in the end, it's up to you how you want to maintain your branch's commit history😃. Whatever you choose, May the force be with you!
If you have reached here, then I did a satisfactory effort to keep you reading. Please be kind to leave any comments or ask for any corrections. Happy Coding!
Top comments (0)