Assuming that you know the names of all integration and release branches, you can find all merge bases and compare (or sort) them by timestamps.
For example, if main branches are named master
and develop
, you can find merge bases between feature branch and each of main branches:
branch_name="feature/feature-1"
is_feature_branch=false
git checkout $branch_name
mb_develop=$( git merge-base HEAD develop )
mb_master=$( git merge-base HEAD master)
ts_develop=$( git show -s --format=%ct $mb_develop)
ts_master=$( git show -s --format=%ct $mb_master)
if (( $ts_develop > $ts_master ))
then
is_feature_branch=true
fi
Admittedly, this approach may be problematic, if there are many more main branches (e.g. develop, master, release/1.0, release/1.1 etc.) or you do not know the name of every main branch in repository.