How to Add Extra Information to Commits with Git Notes
In a hurry? Watch our brief 1-minute vertical video that summarizes the info below.
Have you ever wanted to add some information to a commit after it has been created? Since commits in Git are immutable, you can't change them.
However, Git provides a clever solution for this: git notes!
Git Notes allows you to attach extra information, or "notes", to any commit without changing the commit's hash. This is perfect for adding context like bug tracker IDs, QA notes, or any other metadata.
Adding and Viewing Notes
To add a note to the most recent commit, you can use the git notes add command with the -m flag:
$ git notes add -m "Fixes bug #123" HEAD
If you want to add a more detailed note, you can omit the -m flag, and Git will open your default text editor.
You can also specify a particular commit hash:
$ git notes add <commit-hash>
To see the note for a specific commit, use git notes show:
$ git notes show <commit-hash>
Managing Your Notes
To see a list of all your notes, you can use the git notes list command. This will show you the hash of the note object and the hash of the commit it's attached to.
$ git notes list
If you want to remove a note from a commit, simply use git notes remove:
$ git notes remove <commit-hash>
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Sharing Notes with Your Team
It's very important to understand that notes are not shared with your team by default. A git push or git pull will not include notes.
To share your notes, you must explicitly push the notes reference:
$ git push origin refs/notes/commits
Similarly, to get notes from a remote repository, your collaborators must fetch them explicitly:
$ git fetch origin refs/notes/commits:refs/notes/commits
After you've done this once, Git will remember to keep the notes in sync on subsequent push and fetch operations for that repository.
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.