<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mohamed Saleh</title>
    <description>The latest articles on Forem by Mohamed Saleh (@salehmdev).</description>
    <link>https://forem.com/salehmdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F347030%2F3be77700-8a11-4f02-a3fb-402a3ce3d054.png</url>
      <title>Forem: Mohamed Saleh</title>
      <link>https://forem.com/salehmdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/salehmdev"/>
    <language>en</language>
    <item>
      <title>Setting up a .NET 5 web API + Running it in Docker // for beginners</title>
      <dc:creator>Mohamed Saleh</dc:creator>
      <pubDate>Mon, 27 Sep 2021 23:13:31 +0000</pubDate>
      <link>https://forem.com/salehmdev/setting-up-a-net-5-web-api-running-it-in-docker-for-beginners-2np9</link>
      <guid>https://forem.com/salehmdev/setting-up-a-net-5-web-api-running-it-in-docker-for-beginners-2np9</guid>
      <description>&lt;p&gt;Hey there! 👋🏼&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll be setting up a .NET 5 web API and running it locally, then we'll take a look at how to build and run it inside of a Docker container.&lt;/p&gt;

&lt;p&gt;To set up the project, we'll be using the dotnet CLI -- which is cross-platform and is included with .NET 5 SDK!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why web API?
&lt;/h2&gt;

&lt;p&gt;The .NET team has provided multiple useful templates that can be used when creating a project. Whenever you choose one of them, they set up the project skeleton pre-made to include commonly used packages and folder structure (this is called &lt;em&gt;scaffolding&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;We're using the &lt;code&gt;webapi&lt;/code&gt; template to help scaffold our project. The web API template is a great starting point for building out a standard API because it sets you up with a common folder structure.&lt;/p&gt;

&lt;p&gt;It also doesn't bloat your project with any extra packages, other than &lt;code&gt;Swashbuckle.AspNetCore&lt;/code&gt; for &lt;a href="https://swagger.io/docs/specification/2-0/what-is-swagger/"&gt;Swagger&lt;/a&gt; support.&lt;/p&gt;

&lt;p&gt;We'll be using Swagger to see if our API is running locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dotnet.microsoft.com/download/dotnet/5.0"&gt;.NET 5 SDK&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.docker.com/products/docker-desktop"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the .NET 5 SDK and Docker are installed, you should be able to use the CLI commands. &lt;/p&gt;

&lt;p&gt;To check, you can run these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If those return the version, you should be ready to go!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Dh_cxhK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632533752780/OepdHgwmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Dh_cxhK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632533752780/OepdHgwmn.png" alt="image.png" width="805" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see an error message saying your system doesn't recognize &lt;code&gt;dotnet&lt;/code&gt; or &lt;code&gt;docker&lt;/code&gt;, make sure it's installed properly for your system. You may need to refresh your terminal so it has access to the command line PATH.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the project locally
&lt;/h2&gt;

&lt;p&gt;Let's run &lt;code&gt;dotnet new webapi -o &amp;lt;folder&amp;gt;&lt;/code&gt;. The folder is what you want your project to be called; mine is called &lt;code&gt;AdventureWorks.Api&lt;/code&gt;. Feel free to use that 👍🏼&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new webapi &lt;span class="nt"&gt;-o&lt;/span&gt; AdventureWorks.Api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After a few seconds, the project should be created and all set!&lt;/p&gt;

&lt;p&gt;To test out the project and see it in action, in the project folder run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run &lt;span class="nt"&gt;-p&lt;/span&gt; AdventureWorks.Api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UIvYgJi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632624601836/fdyi5AniywE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UIvYgJi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632624601836/fdyi5AniywE.png" alt="image.png" width="580" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will build out the project and start a local development server on your computer on (by default) port 5001. Let's check it out by going here:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://localhost:5001/swagger&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tRnlgqQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632619894607/LfCn8HZps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tRnlgqQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632619894607/LfCn8HZps.png" alt="image.png" width="880" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cool, the API is up and running locally!&lt;/p&gt;
&lt;h2&gt;
  
  
  Running the project in a Docker container
&lt;/h2&gt;

&lt;p&gt;We'll now go over how to run the project within Docker. The difference here is that we'll set up instructions for Docker to do the work of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;building the project&lt;/strong&gt; - gathering dependencies and compiling&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;publishing the project&lt;/strong&gt; - preparing and optimizing it for "release"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;creating the running docker container&lt;/strong&gt; - contains the running web API project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason all these steps are used, instead of the steps used to run it locally, is that this is how you'd bundle a typical project in .NET for production. Meaning this way of building the docker image, and running a container based on that image, is optimized and ready to be shipped to users.&lt;/p&gt;

&lt;p&gt;This docker build can be used to build out projects for real-world use!&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's try it
&lt;/h3&gt;

&lt;p&gt;Create a file, called &lt;code&gt;Dockerfile&lt;/code&gt;, which will contain the Docker build instructions.&lt;/p&gt;

&lt;p&gt;Then paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Base image used to create the final image&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;mcr.microsoft.com/dotnet/aspnet:5.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 80&lt;/span&gt;

&lt;span class="c"&gt;# Build image which builds the project and prepares the assets for publishing&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;mcr.microsoft.com/dotnet/sdk:5.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /src&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; ["AdventureWorks.Api.csproj", ""]&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;dotnet restore &lt;span class="s2"&gt;"./AdventureWorks.Api.csproj"&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; "/src/."&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;dotnet build &lt;span class="s2"&gt;"./AdventureWorks.Api.csproj"&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; Release &lt;span class="nt"&gt;-o&lt;/span&gt; /app/build

&lt;span class="c"&gt;# Publish image which sets up the optimized version of the app into a folder&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;publish&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;dotnet publish &lt;span class="s2"&gt;"./AdventureWorks.Api.csproj"&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; Release &lt;span class="nt"&gt;-o&lt;/span&gt; /app/publish

&lt;span class="c"&gt;# Final image which only contains the published content of the project&lt;/span&gt;
&lt;span class="c"&gt;# This is where the resulting files of the published app are moved to&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;final&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=publish /app/publish .&lt;/span&gt;
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["dotnet", "AdventureWorks.Api.dll"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: There are comments included for each segment so we can understand what Docker is doing in each step.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;Dockerfile&lt;/code&gt; now contains all the necessary steps for building out the image which will be used to run the app in a container. To build the docker image using the &lt;code&gt;Dockerfile&lt;/code&gt;, within the project folder run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; adventureworks.api &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker build&lt;/code&gt; - Used for building docker images from Dockerfiles&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t adventureworks.api&lt;/code&gt; - This adds a tag name to the image &lt;code&gt;adventureworks.api&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; - This is saying the Dockerfile is located here&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After loading and going through the steps, docker should have downloaded all required dependencies and followed the steps within the Dockerfile.&lt;/p&gt;

&lt;p&gt;There should now be an image created with a repository named &lt;code&gt;adventureworks.api&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P2KbnW8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632713050569/BVZLYGZh_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P2KbnW8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632713050569/BVZLYGZh_.png" alt="image.png" width="707" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is great, this is the final image that we're after which uses as little space possible. Running a container based on this image should be the published version of the app!&lt;/p&gt;

&lt;p&gt;To run this image, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 5151:80 adventureworks.api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker run&lt;/code&gt; - Used for running a process in an isolated container&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 5151:80&lt;/code&gt; - Tells docker to map our local port 5151 to port 80 within the container (which is exposed during the build process in our Dockerfile!)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;adventureworks.api&lt;/code&gt; - The target image to use as a blueprint for the created container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: You may have noticed we're now using port &lt;strong&gt;5151&lt;/strong&gt; this time. This is to help us distinguish local, or container, by having them on different ports!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PopG7QUQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632713810333/SohpGwLZi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PopG7QUQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632713810333/SohpGwLZi.png" alt="image.png" width="538" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app is now up and running within a docker container! 🎊🎉&lt;/p&gt;

&lt;p&gt;To check out the app running in the docker container, we actually can't use the swagger page like before because this app is a release version. Swagger is set up in the &lt;code&gt;Startup.cs&lt;/code&gt; file to only run in development mode!&lt;/p&gt;

&lt;p&gt;We can see the app running by navigating to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:5151/weatherforecast&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oY5fbcTB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632714255941/1GVmhzEEe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oY5fbcTB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1632714255941/1GVmhzEEe.png" alt="image.png" width="880" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: It's using &lt;code&gt;http://&lt;/code&gt; because the app hasn't been set up to use &lt;code&gt;https://&lt;/code&gt; in the container.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you've followed along this far and see the data from that endpoint, congrats! You've successfully run the API in a container! 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing thoughts
&lt;/h2&gt;

&lt;p&gt;Thank you so much for coming this far in this tutorial! 😀&lt;/p&gt;

&lt;p&gt;To recap, we've:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;built a simple .NET 5 app and ran it locally&lt;/li&gt;
&lt;li&gt;ran the app within a docker container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;If you're new to Docker, be sure to clean up any unused containers, images, and resources that you no longer need (if you want to free up storage space). You can learn more about that &lt;a href="https://docs.docker.com/config/pruning/"&gt;using the official docs&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;I hope you've enjoyed this tutorial or found it helpful. If you did, please let me know. Feedback and comments are welcome!&lt;/p&gt;

&lt;p&gt;You can get in touch with me on &lt;a href="https://twitter.com/salehmdev"&gt;Twitter&lt;/a&gt;. Follow if you'd like to see more content like this, your support is greatly appreciated! 🔥&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/salehmdev?ref_src=twsrc%5Etfw"&gt;Follow @salehmdev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your thoughts. ✌🏼&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows"&gt;https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>docker</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Consistent Git Commit Messages Using a Template</title>
      <dc:creator>Mohamed Saleh</dc:creator>
      <pubDate>Sun, 19 Sep 2021 17:26:37 +0000</pubDate>
      <link>https://forem.com/salehmdev/consistent-git-commit-messages-using-a-template-3ono</link>
      <guid>https://forem.com/salehmdev/consistent-git-commit-messages-using-a-template-3ono</guid>
      <description>&lt;p&gt;One way to improve the consistency of your commits is to use a git template.&lt;/p&gt;

&lt;p&gt;Any time you start a new commit, this template will be &lt;strong&gt;pre-loaded&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That means you'll be able to use git commit &lt;em&gt;comments&lt;/em&gt; with some guidelines and reminders!&lt;/p&gt;

&lt;p&gt;This can be useful because it can help remind you of things you typically would include in a git commit message; it could even act as a line length guide!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: You don't &lt;strong&gt;need&lt;/strong&gt; to comment out all the contents of your git commit template.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is simply a common usage but not required... but why would you want all of your commits messages to have the same message?&lt;/em&gt; 🙂&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;First off, in your home directory, create a file with a commonly used name: &lt;code&gt;.gitmessage&lt;/code&gt;. &amp;lt;- This is where you'll store the contents of this template.&lt;/p&gt;

&lt;p&gt;Here's an example template that I personally use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Commit title - 50 characters ------------------|


# Commit body - Line Width 72 characters ------------------------------|


# References, issue #, ticket #, etc:


# Any co-authors:
# Co-authored-by: LastName, FirstName &amp;lt;email@email.com&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: the line length guides only work for monospaced fonts, i.e., each character has the same width.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I prefer it short and to the point -- but you can include whatever you like in here.&lt;/p&gt;

&lt;p&gt;Now, the last step to make it automatically pre-populate your git commit messages is to set it in your git config.&lt;/p&gt;

&lt;p&gt;To do it through the command line, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global commit.template ~/.gitmessage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR &lt;/p&gt;

&lt;p&gt;You can manually set the commit template through your global &lt;code&gt;.gitconfig&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;e.g.: &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1631937446887%2FdJZTE65Lh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1631937446887%2FdJZTE65Lh.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrapping Up
&lt;/h3&gt;

&lt;p&gt;You should be all set!&lt;/p&gt;

&lt;p&gt;Now every time you &lt;code&gt;git commit&lt;/code&gt; in your project repo, you'll get a pre-loaded template that you can edit for your commit message.&lt;/p&gt;

&lt;p&gt;Hope this helps you write better git commits!&lt;/p&gt;

&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;p&gt;Learn more about git best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://chris.beams.io/posts/git-commit/" rel="noopener noreferrer"&gt;https://chris.beams.io/posts/git-commit/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A more in-depth guide about git commit templates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/lisawolderiksen/a7b99d94c92c6671181611be1641c733" rel="noopener noreferrer"&gt;https://gist.github.com/lisawolderiksen/a7b99d94c92c6671181611be1641c733&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
