Yes, this is a good idea and fairly standard (but not universal) practice.
The specific software engineering goal you are achieving with this is requirements traceability. The idea is you want to be able to trace a requirement through the entire software process:
- Business requirements
- Functional requirements
- Technical requirements
- Code artifacts
- QA feedback
- Development fixes
By using ticket or requirement numbers (e.g. Jira story IDs) in commit messages and any correspondence, you are working toward that software engineering goal.
If I come back a year later and see the commit message, I can look up that number in another system to get the full background behind the requirement or ticket, including anything that occurred after the commit.
Answer from user22815 on Stack Exchangeversion control - Is there any downside to commit messages containing the ticket number - Software Engineering Stack Exchange
Customize commitlint with conventional commit + JIRA Ticket - Stack Overflow
git - Should ticket/PR number be in commit header - Stack Overflow
How to configure commitlint for conventional commits with JIRA ticket integration
Yes, this is a good idea and fairly standard (but not universal) practice.
The specific software engineering goal you are achieving with this is requirements traceability. The idea is you want to be able to trace a requirement through the entire software process:
- Business requirements
- Functional requirements
- Technical requirements
- Code artifacts
- QA feedback
- Development fixes
By using ticket or requirement numbers (e.g. Jira story IDs) in commit messages and any correspondence, you are working toward that software engineering goal.
If I come back a year later and see the commit message, I can look up that number in another system to get the full background behind the requirement or ticket, including anything that occurred after the commit.
The downside is that people will write less complete commit comments because someone can go to the ticket for more details. This is only really a problem if you say switch to a different ticketing system and can't keep the history or someone doesn't have ticketing system but does have access to the repository.
If the branch is already named for the ticket I wouldn't bother putting it in the commit, that does seem redundant.
This is asking for an opinion. I try to keep my commit messages self contained so that it makes sense to people without having to connect to github (after all, what use is a distributed SCM tool if you need to connect to a site to see what's going on). However, github provides some useful hooks to close bugs by number so a "closes #42" in a commit message is not an overkill but it should be in the description rather than the header.
I agree with you in principle, the less clutter in the commit Subject line the better. I wouldn't say though that these references are useless for humans though, because many tools can automatically link ticket ids to the corresponding ticket in a log overview (where oftentimes only the subject line is shown by default). Still, the subject line should provide enough context to reveal what the commit is about, without requiring the reader to follow links.
For GitHub ticket ids one has to be careful though, to not put them at the start of the line, because they start with a # which is interpreted as a comment line by git so it will not be included in the message.
I think technically the best solution would be to put related ticket numbers as "metadata" into commit message trailers. If the industry could agree on common conventions there, tools could support that as well, but until that happens I suppose people will continue to use the subject line for ticket ids.