Pankaj Bagwan
Pankaj Bagwan
2 min read

Categories

Tags

Git is most popular distributed version control system used by developers now a days. And most popular workflow being used is of feature-branch-workflow. In this developer working on feature would shoot off a new branch called feature-branch and give it a meaningful name.

Feature branch having meaningful name is great as developers can have an idea what may be going into that branch and in addition one need not to remember branch name

TL;dr

//instead of traditional merge
git merge api_development_order
//do squashed merge
git merge api_development_order --squash

Merge

Just for the purpose of illustration, let’s assume developer Foo have to work on a feature to build an API endpoint to expose orders. To start working on it developer Foo would create an offshoot branch api_development_order from development branch. Let’s also assume developer Foo is done implementing API feature with 20 odd commits to api_development_order branch.

Once the developer is done working with the feature; next task is to merge this branch back into development branch. To accomplish that, developer Foo decides to merge branch back into development branch using following command

git checkout development
git merge api_development_order

But command above will create scattered merge with an additional merge commit. Now in future, if developer Foo needs to revisit this feature, he/she needs to search those scattered commits. Tedious and tiring, isn’t it?

To overcome this issue; developer Foo should have squashed merged his/her changes back into development branch. So obvious question that you may have at this point is; How?

Squash Merge

In squash-merge; git collects all changes that are different from branch we are merging into (basically a cherry diff) and creates a single commit while persisting all commit’s Git SHA and their messages.

This way, in future; when developer Foo or anybody wants to revisit the feature api_development_order; they can simply find it under a single squashed commit. Following are command to squash merge a commit into another branch

git checkout development
git merge api_development_order --squash

Commands; illustrated above would open git message dialog; just have a meaningful message and merge


About The Author

I am Pankaj Baagwan, a System Design Architect. A Computer Scientist by heart, process enthusiast, and open source author/contributor/writer. Advocates Karma. Love working with cutting edge, fascinating, open source technologies.

  • To consult Pankaj Bagwan on System Design, Cyber Security and Application Development, SEO and SMO, please reach out at me[at]bagwanpankaj[dot]com

  • For promotion/advertisement of your services and products on this blog, please reach out at me[at]bagwanpankaj[dot]com

Stay tuned <3. Signing off for RAAM