Git commit: create a title and description from CLI
Create a Git commit with a separate title and body from the CLI. Use multiple -m flags, -F file input, or commit templates for consistent commit messages.
How can I create a Git commit from the command line that includes both a commit title and a separate commit description (body), similar to the GitHub web interface? When I commit locally, git opens my default editor and I write a message that GitHub then splits into a title and body. Is there a way to provide a nicely formatted title and description directly from the terminal (for example using git commit -m, multiple -m flags, an editor template, or other command-line options)?
You can provide both a commit title (summary) and a separate commit description (body) straight from the terminal: use multiple -m flags (for example git commit -m "Title" -m "Body..."), read a prepared message file with -F, or prefill the editor with a commit template (commit.template or -t). Git treats the text before the first blank line as the commit title and the rest as the body — the same split that GitHub shows.
Contents
- Quick answer: how Git splits title and body
- Use multiple -m flags with git commit
- Provide a commit message from a file with -F
- Commit templates and commit.template (prefill the editor)
- Edit after -m, amend, and cleanup options
- Examples and best practices for commit messages
- Sources
- Conclusion
Quick answer: git commit with a title and body
Short version: yes. The CLI supports several ways to give a nicely formatted commit title and a separate description without manually typing everything into your editor. The easiest options are:
- Use multiple
-mflags:git commit -m "Short summary" -m "Longer description...". Each-mbecomes a paragraph; the first paragraph is treated as the title. See the official manual for the option details: Git - git-commit Documentation. - Use
-F <file>to read the whole message (title on the first line, blank line, then body) from a file. - Use a commit template (
git config commit.template <file>orgit commit -t <file>) sogit commitopens your editor pre-filled with a structured message.
All hosting providers and tools (including GitHub) display the first paragraph as the summary/title, so these CLI techniques produce the same split you see on the web.
Use multiple -m flags with git commit
Syntax and behavior:
-m <msg>sets a commit message. If you pass multiple-moptions, Git concatenates them as separate paragraphs (it inserts a blank line between them). The first paragraph becomes the commit title/summary. See the manual: https://git-scm.com/docs/git-commit.
Example:
git add file.txt
git commit -m "Add login endpoint" -m "Validate inputs and return JSON; add unit tests."
Resulting commit message (what git stores and what GitHub shows):
Add login endpoint
Validate inputs and return JSON; add unit tests.
Shell tips and alternatives:
- On shells that support ANSI-C quoting (bash), you can include literal newlines inside a single
-mwith$'...':
git commit -m $'Short summary\n\nLonger description line 1\nLine 2'
That relies on your shell to produce actual newline characters; the -m flag then receives a multi-line string.
- If the body is long or maintained in a file, prefer
-m+-mor-Frather than embedding complex quoting in a one-liner.
For a short guide confirming multiple -m usage, see the phoenixNAP tutorial: https://phoenixnap.com/kb/git-commit.
Use a file with -F to provide title + body
When you already have the message written (or want to script it), create a file where the first line is the title, a blank line separates the body, then the body text follows.
Example (here-doc to create a temp message file):
cat > /tmp/commit-msg.txt <<'EOF'
Fix crash when user ID is nil
Guard against nil user IDs in the session handler. This avoids a
runtime exception when a request arrives with a missing id field.
Added unit test and an integration test case.
EOF
git add .
git commit -F /tmp/commit-msg.txt
Notes:
- The file format is plain text: first paragraph → summary, remaining paragraphs → body.
- Lines that start with
#are commonly used as comments in templates/editors and are ignored by Git when editing messages; templates and editor workflows often show commented guidance lines. See community examples on templates and multiline messages: https://gitscripts.com/git-commit-multiline-message.
Commit templates and commit.template
If you want a consistent structure for every commit (prefixes, checklists, placeholders), use a commit template:
- Create a template file, e.g.
~/.gitmessage:
Short summary (50 chars or less)
- Why:
- What:
- How:
- Configure Git to use it:
git config --global commit.template ~/.gitmessage
- Run
git commitas usual. Your editor opens pre-filled with the template; fill in the lines and save.
You can also call a specific template for a single commit with git commit -t /path/to/template. Templates are handy when teams want consistent fields (issue number, changelog blurb, etc.). See an example write-up on global commit templates: https://www.stefanjudis.com/today-i-learned/global-git-commit-templates/ and a community guide: https://dev.to/albz/level-up-your-git-commits-with-custom-templates-5786.
Edit after -m, amend, and cleanup options
Want to prefill a message but still tweak it in your editor? Use -e (or --edit) together with -m or -F:
git commit -m "Draft title" -e
That opens the editor with the provided message preloaded so you can refine the body.
To change the most recent commit message (for local edits before pushing), use --amend:
git commit --amend -m "New title" -m "New body..."
# or
git commit --amend -F /tmp/new-message.txt
Cleanup: Git can clean up and remove comments/whitespace lines from messages; the --cleanup option controls this behavior (see git commit --help).
Examples and best practices for commit messages
Quick examples:
- Minimal, no editor:
git commit -m "Fix typo in README" -m "Corrected the installation example and added missing flag note."
- From a file:
git commit -F ./commit-message.txt
- Template + commit:
git config --global commit.template ~/.gitmessage git commit
Best-practice format (widely used):
- Title: one short line, ~50 characters, imperative mood (e.g., “Add user login”).
- Blank line.
- Body: explain the why and how; wrap at ~72 characters.
Why follow this? Tools and hosting sites expect the first paragraph to be the summary and show it in lists and PR titles. Clean, consistent messages make history easier to scan and automate.
Want to avoid opening the editor every time? Use -m twice or prepare a message file and use -F. For scripting, git commit -m "Title" -m "Body..." is simple and portable. For team consistency, use a commit.template.
Sources
- Git - git-commit Documentation
- git commit: How to Make a Commit — phoenixNAP
- How to apply a global Git commit template | Stefan Judis
- Mastering Git Commit Multiline Message: A Quick Guide — GitScripts
- How to Commit Multiline Messages in git commit — WebDeveloper / Beehiiv
- Level Up Your Git Commits with Custom Templates — DEV Community
- Understanding Git Commit — GitGopher
- How to Use GitHub Repository Templates — GitProtect.io blog
- Commit in GitKraken Desktop | How to Commit Changes
- GitHub Docs — committing changes (fetched as part of research)
Conclusion
You can create a Git commit with both a title and a separate description directly from the CLI using git commit -m "Title" -m "Body...", git commit -F <file> (file with a blank line between title and body), or by using commit templates (commit.template or -t) to prefill the editor. Use -e to edit after providing a message and --amend to rewrite the last commit. Follow the conventional format (short summary, blank line, wrapped body) so your commit message displays cleanly in GitHub and other tools.