# 📘 Git Rule Specification: Ensure Git User Name and Email Are Configured
**Rule ID**: `RULE_git-name-email-setup`
**Status**: Draft
**Updated**: 2025-04-26
**Version**: v1.0.0
**RuleLevel**: Error
---
## 1. Summary
> Verify that both `user.name` and `user.email` are set in Git configuration before allowing commits.
## 2. Scope
### Applies To:
- [x] Developers (local)
- [x] CI/CD pipelines
- [ ] GitHub/GitLab Web UI
- [x] Hooks (pre-commit, pre-push, etc.)
- [ ] Git config/templates
### Affects:
- [x] Commits
- [ ] Branching
- [ ] Merges
- [ ] Pushes
- [ ] Repository layout
- [ ] Miscellaneous
### Trigger Point (When to Check):
Before `git commit` is executed, either locally or in automated pipelines.
---
## 3. Motivation
### Problem Statement:
Commits without a configured user name or email may lead to anonymous or incorrect attribution, complicating code ownership tracking and audit trails.
### Objectives:
- Ensure that every commit is properly attributed to a real author.
- Prevent anonymous or placeholder commits in shared repositories.
- Enforce consistent commit metadata across all environments.
### Common Pitfall:
A developer clones a repository on a new machine and runs `git commit` without first configuring `user.name` and `user.email`, resulting in an anonymous commit with no clear author.
---
## 4. Rule Definition
### Description:
This rule checks for the presence of both `user.name` and `user.email` in the Git configuration at commit time.
**Allowed:**
- Commits when both `git config --get user.name` and `git config --get user.email` return non-empty values.
**Forbidden:**
- Commits when either `user.name` or `user.email` is unset or empty.
---
## 5. Examples
### ✅ Correct Usage
```bash
$ git config --get user.name
Alice Developer
$ git config --get user.email
alice@example.com
$ git commit -m "Add new feature"
[main abc123] Add new feature
```
### ❌ Incorrect Usage
```bash
$ git config --get user.name
$ git config --get user.email
$ git commit -m "Fix bug"
Error: Git user.name and/or user.email is not configured. Please set them before committing.
```
## 6. Impact Assessment
### Frequency of Violation:
- [x] Rare
- [ ] Occasional
- [ ] Frequent
### Severity When Violated:
- [ ] Pedantic (nice to have)
- [ ] Low (minor inconvenience)
- [x] Medium (requires cleanup)
- [ ] High (code breakage, data loss)
- [ ] Critical (security/legal risk)
---
## 7. Enforcement Strategy
### Pseudocode / Workflow
```bash
# In pre-commit hook or commit wrapper
echo "Run:"
echo " git config --global user.name \"Your Name\""
echo " git config --global user.email \"you@example.com\""
exit 1
fi
```
### Suggested Tooling:
* POSIX-shell pre-commit hook
* CI pipeline step before build/tests
* Custom CLI wrapper around `git commit`
## 8. Possible Fixes
### Manual Fix:
```bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```
### Automated Fix Suggestions:
None (requires user-provided identity information).
## 9. Exceptions & Edge Cases
* Bypass allowed in ephemeral or CI contexts where commits are generated by automation and a machine identity is pre-configured.
* Projects with monorepo workflows that explicitly inject commit metadata via environment variables may exempt this check.
## 10. Drawbacks
Enforcing this rule may block automated scripts that generate commits unless they explicitly configure a service identity in advance.
## 11. Related Rules / RFCs
* `RULE_git-version-consistency`
* `RULE_protect-main-branch`
## 12. Revision History
| 2025-04-26 | 1.0.0 | Himanshu Sharma | Initial draft |
## 13. Glossary
| CI | Continuous Integration |
| Hook | Git hook script (e.g. `pre-commit`, `pre-push`) |
## 14. References
* https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
* https://git-scm.com/docs/git-config#Documentation/git-config.txt---getltnamegt