[Shell] How to get the remote default branch in Git

--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.

result

--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

reference

Recommended Posts

[Shell] How to get the remote default branch in Git
How to get help in an interactive shell
How to get the files in the [Python] folder
How to get the variable name itself in python
How to get the number of digits in Python
One liner to get the nth commit hash in Git
How to get the Python version
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
How to intentionally issue an error in the shell During testing
How to get all the possible values in a regular expression
How to get the vertex coordinates of a feature in ArcPy
How to get a stacktrace in python
How to get colored output to the console
How to get the date and time difference in seconds with python
How to use the C library in Python
Log in to the remote server with SSH
How to get results from id in Celery
Use pygogo to get the log in json.
How to pass the execution result of a shell command in a list in Python
How to get the notebook name you are currently using in Google Colab
How to get a list of files in the same directory with python
How to retrieve the nth largest value in Python
How to run the Ansible module added in Ansible Tower
How to get multiple model objects randomly in Django
How to know the current directory in Python in Blender
How to use the exists clause in Django's queryset
How to change static directory from default in Flask
How to use the model learned in Lobe in Python
[Python] How to output the list values in order
How to get RGB and HSV histograms in OpenCV
linux / c> link> Get the execution result of the shell command in the C program> I was taught how to use popen ()
How to find the optimal number of clusters in k-means
[python] How to check if the Key exists in the dictionary
How to get rid of server custom emoji in message.content
[Go language] How to get terminal input in real time
How to debug the Python standard library in Visual Studio
How to use the generator
How to use the __call__ method in a Python class
Get the package version to register with PyPI from Git
Rename and replace remote files using NcFTP in the shell
[OCI] Python script to get the IP address of a compute instance in Cloud Shell
How to set the html class attribute in Django's forms.py
How to manipulate the DOM in an iframe with Selenium
How to log in automatically like 1Password from the CLI
I tried "How to get a method decorated in Python"
Get the value while specifying the default value from dict in Python
How to generate a query using the IN operator in Django
How to get Instruction Pointer (= program counter) in Linux kernel
How to get a list of built-in exceptions in python
In Django, how to abbreviate the long displayed string as ....
Notes on how to use marshmallow in the schema library
How to get an overview of your data in Pandas
How to execute external shell scripts and commands in python
How to use the decorator
How to get a quadratic array of squares in a spiral!
How to pass the execution result of a shell command in a list in Python (non-blocking version)
[Introduction to Python] How to get data with the listdir function
How to increase the axis
How to start the program
Memo of the program to get the date in two digits with javascript, Ruby, Python, shell script