Keeping that in mind, Git introduced the feature of defining the template for the commit message that permits you to handle such scenarios. You can define a commit message template which will appear on every user interface when committing.
This write-up will provide the instructions to define a Git commit message template.
How to Define a Git Commit Message Template?
To define a Git, commit message template, the “.gitmessage” file is utilized. You can define the commit message template inside this file and add it in your main directory. Let’s dive into the practical demonstration of doing this.
Step 1: Move to Project Directory
First, open the terminal, and move to your project directory:
Step 2: Create “.gitmessage” File
Afterward, create the “.gitmessage” file with the touch command:
The file “.gitmessage” has been created.
Step 3: Define Commit Message Template
After creating the “.gitmessage” file, open it with the nano editor and define the commit message template. For instance, we have added the 3 portions, subject, body, and footer. You can define the template as per your needs and preferences:
<Enter Subject with Short Description>
<Enter Detailed Description of the Changes You Have Made>
<Enter Additional Information Like References>
Save the file and exit from the editor.
Step 4: Set Template to Default
For the default calling of this template in your main project, run this command in the terminal:
The file “.gitmessage” is set to default for the commit message template.
Step 5: Check the Set Template File
To verify and check the template file is set to default or not, the following command is considered:
Step 6: Commit to Verify
Now, run the “git commit” command in the terminal and you will get the defined template in the editor:
You can define a Git template by following these instructions.
To define a Git, commit message template, create the “.gitmessage” file inside your main project directory and define the template inside it. After that, execute the “git config –local commit.template .gitmessage” command to set the “.gitmessage” to default. Verify the results by committing a message in the directory. This write-up has demonstrated the steps to define a Git commit message template.