Thoughts on Diverged branches

Hello all, I am new to this forum and just wanted to get feedback on my thoughts…

I have a master branch and an integration branch. Obviously master is my default branch. Integration is used to push new features to, test, and validate everything. Once a few criteria is met, a PR is initiated to go from integration to master. However, recently I have run into an issue. Integration and master are identical, word for word, bit for bit, but when I look on github, it shows that integration is 20 commits behind master and 95 commit ahead of master. I believe that this is because when merging from integration to master the commits were squashed. (The 20 commits behind are things that were put directly into master because they were needed beforehand). There are two options I could think of here but not sure which is the most optimal.

  1. Revert the last squashed commit into master and perform a PR on the 94 commits from integration to master. A git pull will need to be done to resolve the 20 commits behind master but that is not a big deal.

  2. Delete integration and create another branch tracking master and call it integration. I do not want to mess other developers up who are tracking integration though.

If you rebase integration on top of master with the command:

git rebase master

when your active branch is integration, then it will attempt to “replay” the commits in integration on top of master. Since all of the changes that are in integration are already present in master, it should realize this and result with integration and master being equivalent with no commits ahead or behind.

Or you can just delete the integration branch and create it anew. There’s really no difference in the end.

This potential to fall out of sync is one of the drawbacks of “long running” branches and why the common wisdom is to create a new branch for each feature, bug fix, or other change, then merge the branch into master and delete the feature branch when you’re done. Alternatively, you could squash commits on the integration branch before the merge, then merge the squashed commits from integration to master. This way integration and master would have the same commits and not fall out of sync like you experienced.