At work we have a GIT-branching model where every major release version of our product has a separate branch.
The V2.0 branch contains all commits that the v1.0 branch has plus additional work done on v2.0 of the product. V3.0 contains all commits from v1.0 & v2.0 plus additional work done on v3.0 etc.
When making a bugfix/feature, one needs to branch out from the right version of the product where the bugfix/feature needs to be implemented. After a while, you want to rebase your feature branch on top of the latest changes from whatever branch it was you branched out from. Only problem is: it is fairly easy to make a mistake and pick to wrong version branch (v2.0 instead of v1.0 for example). You wouldn’t really get any conflicts either, because all newer version branches contain all commits from the lower version branches plus additional commits.
I am working on a GIT-hook (pre-rebase) that would warn the user that he/she is likely rebasing on top of the wrong version branch.
What I came up with so far, is comparing tags between the local feature branch and the remote branch. As the v1.0 branch has a v1.0 tag, and the v2.0 branch also has a v2.0 tag. So if the user wants to rebase a feature branch branched out from v1.0 on top of v2.0, there is a difference in tags.
However, this would not work if the developer branched out from the v3.0 branch, but is trying to rebase his branch on top of the master branch, as there are no additional tags on the master branch that the v3.0 branch does not contain.
The next best solution I could come up with, was counting the amount of commits that the remote branch the user is trying to rebase on top of, is ahead. As it is likely that if the user branched out from v1.0, but is trying to rebase on top of v2.0, v2.0 contains hundreds of commits that do not exist on the developers’ feature branch.
I was wondering if anybody could come up with a better solution to prevent the rebaseing/merging of the wrong version branch into ones feature branch?
Edit: we are not able to install any server-side Git-hooks at the moment. We will be sharing git-hooks among developers for now. (knowing that this doesn’t guarantee 100% that wrong merges will not happen.)