--In the case of development using Git, there are cases where the process of acquiring the default branch name with shell or CI is described. --However, since the default name has been changed from ** master ** to ** main ** due to various reasons, it is necessary to obtain it for general purposes. --So, record two ways to get the remote default branch name for your Git source.
--There are two main ways to use the git remote
command.
--Select according to the environment
#For awk
#output: master(or main)
git remote show origin | awk '/HEAD/ {print $NF}'
# grep /In the case of cut
#output: master(or main)
git remote show origin | grep 'HEAD branch' | cut -d' ' -f5
Recommended Posts