Git Naming Conventions…

It was not until recently that I found a good article about naming conventions. As I created more repositories and the complexity of my projects increased, I become much more cognizant of the importance of being organized. There are many different things that can be done to keep a project orderly but here are some specifics related to Git.
Branch Naming
The article that I found was by codingsight.com and their naming rules just make sense. Here are a few takeaways:
- For temporary branches, use a keyword at the beginning hat describes the type of work.
- Bug Fix (bug)
- Hot Fix (hot)
- Feature Branch (feature)
- Experimental Branch (experiment)
- Work in Progress Branch (wip)
- If using Jira or other PMS, use a unique ID within the branch name.
- Use hyphen or slashes as separators. I should probably write more about the effect of using slashes but taht will be a different article.
- Use only lowercase
- Be consistent. Decide early if words are separated by hyphens but don’t mix in underscores or periods unless there is a logical pattern.
- Potentially include the authors name in the name
- For branches that will take a long time to develop, use a short descriptive name.
Here is an example format:
<branch-type>_<author>_<branch-name>
Commit Messages
I don’t really write detailed commit messages. I think about it but I tend to keep all messages very short. Here are a few heuristics from a medium.com article that I do like:
- Keep the subject line under 50 characters long.
- Explanatory text should be written in the imperative verb form - Fix bug causing outage.
- The message should answer these questions:
- Why is this change necessary?
- How does this commit address the issue?
- What effects does this change have?
-
To keep messages shorter then the PMS ID could be added. This is common when using JIRA.
- For larger projects, write a multiline commit message by typing
git commit
. This will open a command line editor. You can also set your default editor with this commandgit config --global core.editor nano
. I actually like to use the command line method:git commit -m "Subject" -m "Description..."
Similar to the medium article, gitkraken.com has a nice article that largely supports the above suggestions.