notes Git Command Guide
The git notes command adds, removes, or reads notes attached to objects, without touching the objects themselves. By default, notes are saved to and read from refs/notes/commits, but this default can be overridden for different note namespaces.
git notes Syntax:
Section titled “git notes Syntax:”git notes [list [<object>]]git notes add [-f] [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [-e] [<object>]git notes copy [-f] ( --stdin | <from-object> [<to-object>] )git notes append [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [-e] [<object>]git notes edit [--allow-empty] [<object>] [--[no-]stripspace]git notes show [<object>]git notes merge [-v | -q] [-s <strategy> ] <notes-ref>git notes merge --commit [-v | -q]git notes merge --abort [-v | -q]git notes remove [--ignore-missing] [--stdin] [<object>...]git notes prune [-n] [-v]git notes get-refNote Management Commands:
Section titled “Note Management Commands:”| Command | Description |
|---|---|
list [<object>] | List notes for object or all notes |
add | Add note to object |
copy | Copy note from one object to another |
append | Append to existing note |
edit | Edit existing note |
show | Display note for object |
merge | Merge notes from different refs |
remove | Remove note from object |
prune | Remove notes for non-existent objects |
get-ref | Show current notes ref |
Note Content Options:
Section titled “Note Content Options:”| Option | Description |
|---|---|
-f, --force | Overwrite existing notes |
--allow-empty | Allow empty notes |
--separator=<break> | Specify paragraph break |
--no-separator | Don’t add separator |
--stripspace | Strip whitespace from note |
--no-stripspace | Preserve whitespace |
-F <file> | Read note from file |
-m <msg> | Specify note message |
-c <object> | Reuse note from object |
-C <object> | Reuse and edit note from object |
-e, --edit | Edit note in editor |
Note Reference Options:
Section titled “Note Reference Options:”| Option | Description |
|---|---|
<object> | Object to attach note to |
<notes-ref> | Notes reference to merge |
-s <strategy> | Merge strategy (manual, ours, theirs, union, cat_sort_uniq) |
Basic Note Operations:
Section titled “Basic Note Operations:”Add Notes to Commits:
Section titled “Add Notes to Commits:”# Add note to specific commitgit notes add -m "Reviewed by QA team" HEAD
# Add note from fileecho "Security review completed" | git notes add -F - HEAD~1
# Add note with editorgit notes add HEAD~2View and List Notes:
Section titled “View and List Notes:”# Show note for specific commitgit notes show HEAD
# List all notesgit notes list
# Show notes for specific commitgit notes show abc123
# List notes with commit infogit notes list | xargs -I {} sh -c 'echo "Note for {}:"; git notes show {}; echo'Edit Existing Notes:
Section titled “Edit Existing Notes:”# Edit note in editorgit notes edit HEAD
# Append to existing notegit notes append -m "Additional review comments" HEAD
# Replace note contentgit notes add -f -m "Updated review status" HEADAdvanced Note Management:
Section titled “Advanced Note Management:”Multiple Note Namespaces:
Section titled “Multiple Note Namespaces:”# Use custom notes refgit notes --ref=reviews add -m "Code review approved" HEAD
# List notes from specific refgit notes --ref=reviews list
# Show notes from custom refgit notes --ref=reviews show HEADNote Copying and Merging:
Section titled “Note Copying and Merging:”# Copy note from one commit to anothergit notes copy HEAD~1 HEAD
# Copy note via stdinecho "abc123" | git notes copy HEAD~1
# Merge notes from different refsgit notes merge reviewsgit notes merge --commit reviewsNote Removal and Cleanup:
Section titled “Note Removal and Cleanup:”# Remove note from commitgit notes remove HEAD
# Remove multiple notesgit notes remove HEAD~1 HEAD~2 HEAD~3
# Remove notes for non-existent commitsgit notes prune
# Dry-run prune operationgit notes prune -nIntegration with Git Workflows:
Section titled “Integration with Git Workflows:”Code Review Integration:
Section titled “Code Review Integration:”# Add review notes during code reviewgit notes add -m "Approved for merge" HEAD
# Add reviewer informationgit notes append -m "Reviewed-by: $(git config user.name) <$(git config user.email)>"
# Mark as reviewedgit notes add -m "Status: approved" HEADRelease Notes Management:
Section titled “Release Notes Management:”# Add release notes to commitsgit notes add -m "Release: v2.1.0 - Added new features" HEAD
# Track deployment informationgit notes append -m "Deployed: $(date) to production"
# Add changelog entriesgit notes add -m "Changelog: Fixed critical security issue" HEADQuality Assurance Tracking:
Section titled “Quality Assurance Tracking:”# Track testing statusgit notes add -m "QA: Passed all tests" HEAD
# Add test coverage informationgit notes append -m "Coverage: 95% - meets requirements"
# Track security reviewgit notes add -m "Security: Approved by security team" HEADNote Formatting and Display:
Section titled “Note Formatting and Display:”Custom Note Display:
Section titled “Custom Note Display:”# Show notes in log outputgit log --notes
# Show notes from specific refgit log --notes=reviews
# Show all notesgit log --notes=*
# Format notes in loggit log --format="%H %s%nNotes:%n%N"Note Content Formatting:
Section titled “Note Content Formatting:”# Configure note formattinggit config notes.displayRef "*"
# Configure note separatorgit config notes.rewriteMode overwrite
# Configure note editorgit config notes.editor vimNote Merging Strategies:
Section titled “Note Merging Strategies:”Merge Strategy Options:
Section titled “Merge Strategy Options:”# Manual merge strategygit notes merge -s manual reviews
# Use ours strategy (keep current)git notes merge -s ours reviews
# Use theirs strategy (overwrite with incoming)git notes merge -s theirs reviews
# Concatenate notesgit notes merge -s cat_sort_uniq reviews
# Union strategygit notes merge -s union reviewsConflict Resolution:
Section titled “Conflict Resolution:”# Abort merge on conflictsgit notes merge --abort
# Commit after manual resolutiongit notes merge --commit
# Verbose merge outputgit notes merge -v reviewsIntegration with External Tools:
Section titled “Integration with External Tools:”Issue Tracker Integration:
Section titled “Issue Tracker Integration:”#!/bin/bash# Add issue references as notescommit_msg=$(git show --no-patch --format=%B HEAD)
# Extract issue numbersissue_ids=$(echo "$commit_msg" | grep -o "#[0-9]\+" | tr '\n' ' ')
if [ -n "$issue_ids" ]; then git notes add -m "Related issues: $issue_ids" HEADfiDocumentation Enhancement:
Section titled “Documentation Enhancement:”# Add documentation links to commitsgit notes add -m "Documentation: https://docs.company.com/feature-xyz" HEAD
# Add API referencesgit notes append -m "API: /api/v2/endpoints"
# Add architectural decisionsgit notes add -m "ADR: Decision to use microservices architecture" HEADPerformance and Maintenance:
Section titled “Performance and Maintenance:”Large Repository Handling:
Section titled “Large Repository Handling:”# Prune notes for deleted commitsgit notes prune -v
# Check notes integritygit notes list | wc -l && echo "notes in repository"
# Clean up old notesgit notes prune --dry-run | head -10Note Backup and Migration:
Section titled “Note Backup and Migration:”# Export notes for backupgit notes list | while read hash; do echo "=== $hash ===" git notes show "$hash"done > notes-backup.txt
# Import notes from backupwhile read hash; do read note git notes add -m "$note" "$hash"done < notes-backup.txtTroubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Note Not Appearing:
Section titled “Note Not Appearing:”# Check if notes existgit notes list | grep "$(git rev-parse HEAD)"
# Check notes refgit notes get-ref
# Verify note contentgit cat-file -p "$(git notes get-ref)":HEADMerge Conflicts:
Section titled “Merge Conflicts:”# Handle note merge conflictsgit notes merge -s manual reviews
# Edit conflicting notegit notes edit HEAD
# Complete mergegit notes merge --commitPermission Issues:
Section titled “Permission Issues:”# Check notes ref permissionsls -la .git/refs/notes/
# Fix permissions if neededchmod 644 .git/refs/notes/commitsEncoding Problems:
Section titled “Encoding Problems:”# Handle special characters in notesgit notes add -m "Note with special chars: äöü" HEAD
# Configure encodinggit config i18n.commitEncoding UTF-8Real-World Usage Examples:
Section titled “Real-World Usage Examples:”Code Review Workflow:
Section titled “Code Review Workflow:”#!/bin/bash# Enhanced code review with notes
# Add review statusgit notes add -m "Review-Status: approved" HEAD
# Add reviewer informationgit notes append -m "Reviewed-by: $(git config user.name)"git notes append -m "Review-Date: $(date)"
# Add review commentsgit notes append -m "Comments: Excellent implementation of feature"
# Mark for mergegit notes add -m "Ready-for-Merge: yes" HEAD
# Generate review summaryecho "=== Review Summary ==="git log --oneline --notes=reviews -1Release Management:
Section titled “Release Management:”# Track release informationgit notes add -m "Release: v3.2.1" HEADgit notes append -m "Release-Date: $(date)"git notes append -m "Release-Notes: Bug fixes and performance improvements"
# Add deployment trackinggit notes append -m "Deployed: $(date) to staging"git notes append -m "Deployed: $(date) to production"
# Track rollback informationgit notes add -m "Rollback: Reverted due to critical bug" HEADCompliance and Auditing:
Section titled “Compliance and Auditing:”# Add compliance informationgit notes add -m "Compliance: SOX compliant" HEADgit notes append -m "Audited-by: compliance-team@company.com"git notes append -m "Audit-Date: $(date)"
# Add security review notesgit notes add -m "Security-Review: passed" HEADgit notes append -m "Security-Reviewer: security-team@company.com"
# Track change approvalgit notes append -m "Approved-by: change-advisory-board"How do notes differ from commit messages?
Section titled “How do notes differ from commit messages?”Notes are separate metadata attached to commits, while commit messages are part of the commit object itself. Notes can be added/removed without changing commit hashes.
Can notes be attached to objects other than commits?
Section titled “Can notes be attached to objects other than commits?”Yes, notes can be attached to any Git object (commits, trees, blobs, tags). Most common use case is commit notes for additional metadata.
What’s the difference between git notes and git tags?
Section titled “What’s the difference between git notes and git tags?”Tags mark specific commits with names, notes attach additional information to any object. Tags are references, notes are separate objects with references.
How do notes work with git log?
Section titled “How do notes work with git log?”Use git log —notes to display notes in log output. Configure notes.displayRef to control which note refs are shown by default.
Can notes be merged between repositories?
Section titled “Can notes be merged between repositories?”Yes, use git notes merge to combine notes from different repositories or note refs. Supports various merge strategies for conflict resolution.
What’s the performance impact of notes?
Section titled “What’s the performance impact of notes?”Notes add minimal overhead - separate objects with references. Large numbers of notes may require occasional pruning of orphaned notes.
How do notes interact with git rebase?
Section titled “How do notes interact with git rebase?”Rebase preserves notes by default. Use —no-notes with rebase if you want to exclude notes from rebased commits.
Can notes contain binary data?
Section titled “Can notes contain binary data?”Yes, notes can contain any content. Use -F option to read from files for binary or large text content.
How do I backup and restore notes?
Section titled “How do I backup and restore notes?”Use git notes list to enumerate notes, git notes show to extract content. Restore by recreating notes on target repository.
What’s the relationship between notes and git describe?
Section titled “What’s the relationship between notes and git describe?”git describe uses tags for naming; notes provide additional metadata. Can combine both for comprehensive commit annotation.
Can notes be used for workflow automation?
Section titled “Can notes be used for workflow automation?”Yes, scripts can parse notes for automation triggers. Use git notes show in scripts to extract metadata for conditional processing.
How do notes work with Git LFS or large files?
Section titled “How do notes work with Git LFS or large files?”Notes work normally with any Git repository. Can annotate commits containing LFS files or any other Git objects.
What’s the difference between notes and git attributes?
Section titled “What’s the difference between notes and git attributes?”Git attributes control Git behavior for files; notes provide metadata about objects. Different purposes - attributes affect Git operations, notes provide information.
Can notes be used for code review workflows?
Section titled “Can notes be used for code review workflows?”Yes, perfect for review workflows. Add review status, reviewer information, approval status, and comments as notes on commits.
How do notes interact with git bisect?
Section titled “How do notes interact with git bisect?”Bisect operates on commit objects, notes are separate. Bisect doesn’t consider note content when finding commits meeting criteria.
Can notes be used for compliance tracking?
Section titled “Can notes be used for compliance tracking?”Excellent for compliance - add audit information, approval status, compliance checks, and regulatory metadata as notes on relevant commits.
What’s the storage overhead of notes?
Section titled “What’s the storage overhead of notes?”Notes are separate objects, so they add to repository size. Each note is a blob object plus reference. Minimal overhead for typical usage.
How do notes work with git worktrees?
Section titled “How do notes work with git worktrees?”Notes work normally with worktrees. Note refs are shared across worktrees, note content available in all worktrees.
Can notes be used for documentation purposes?
Section titled “Can notes be used for documentation purposes?”Yes, attach documentation links, API references, architectural decisions, and other documentation metadata to relevant commits.
How do I handle note conflicts in collaborative workflows?
Section titled “How do I handle note conflicts in collaborative workflows?”Use git notes merge with appropriate strategies. Manual resolution for complex conflicts, automated strategies for simple cases.
Applications of the git notes command
Section titled “Applications of the git notes command”- Code Review Enhancement: Attach review status, comments, and approval information to commits
- Release Management: Track release information, deployment status, and version metadata
- Compliance Auditing: Add regulatory compliance information and audit trails to commits
- Documentation Linking: Attach documentation references and architectural decisions to code changes
- Workflow Automation: Use notes as triggers for automated processes and integrations
- Collaborative Annotation: Enable team members to add contextual information to commits