The short answer is, “yes”. You should use your .gitignore file to ignore the .env file.
Recommendations
.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.
Writing Good Commit Messages is the Wrong Place to Start
I’m a big fan of Git and I’ve worked with lost of developers in growing their Git skills. Often developers learning Git, start by learning how to write a “good” commit message. While writing “good” commit messages is an important skill, in my opinion it is the wrong place to start.
Rules for Writing Git Commit Messages
These are the rules I follow when writing Git commit messages. I’ve found these serve me well and are compatible with most projects I work on (if a project has a specific set of rules for writing Git commit messages, those would override any rules I’ve outlined here).
Add git status to zsh prompt
One of the things that made me much better at Git was making my current branch (and whether or not I have any changed files) always visible. By default zsh includes everything you need to do this, you just need to configure it.
Git warning: Pulling without specifying how to reconcile divergent branches is discouraged
When using Git version 2.27.0 or higher running the command ‘git pull’ will display, “warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull”.
Why __() needs a hardcoded string in WordPress
When using a WordPress translation function, e.g. __(), you need to use a hardcoded string (not a variable).
Zoom Beginner Tips
Lately I’ve been joining Zoom meetings with lots of new users and I find I keep sharing the same tips. The short version is: use Gallery View, Mute Yourself, and take advantage of Chat.
Git Preview Changes in Commit Message
You can set Git to preview all of the changes in your commit when you write your commit message. I find this to be a big help in writing my commits (and reminds me to keep the changes in my commits small).