The short answer is, “yes”. You should use your .gitignore file to ignore the .env file.
gitignore
.gitignore Hidden Files with Exceptions
In most operating systems by default, files that start with a period (.) are hidden. When setting up my .gitignore file, I like to ignore all these hidden files (with a few exceptions).
Starter .gitignore file
This is my general starter .gitignore file for projects. I have a separate .gitignore for WordPress websites.
.gitignore for WordPress
Originally when I started using Git with my WordPress projects, I checked in all the files (WordPress core, plugins, themes, and even uploads). Over time I’ve found that to be less than ideal. My preferred .gitignore file appears below and it ignores everything by default. This allows me to whitelist only those plugins and themes […]