To include literal quotes inside your Git commit message when using the command line, you just need to wrap your entire message in the opposite type of quote, or use a backslash (\) to escape them.
Method 1: Mix Your Quotes
The easiest approach is to alternate between single and double quotes depending on what you need to type.
To include single quotes or apostrophes: Wrap the whole message in double quotes.
git commit -m "Fixed the issue that can't get latest data"
To include double quotes: Wrap the whole message in single quotes.
git commit -m 'Added the "feature-flag" configuration'
Method 2: Escape the Quotes
If you are already wrapping your message in double quotes and want to include literal double quotes inside it, use a backslash (\) directly before the inner quotes.
git commit -m "This message contains \"double quotes\" inside it"
Method 3: Use an External Editor (Best for Complex Messages)
If your terminal shell is making quotes or special characters difficult to type, omit the -m flag entirely.
git commit
This command automatically opens your default command-line text editor like Vim, Nano, or VS Code. Inside the text editor, you can type single and double quotes normally without worrying about command-line syntax rules. Once you save and close the file, Git applies your exact text as the commit message.
Leave a Reply