How to fix warning: path 'file.txt' contains non-UTF-8 characters in Git
This Git warning appears when a filename contains characters that are not valid UTF-8 encoding. It commonly occurs with files created on systems using different character encodings (like Latin-1 or Windows code pages) and can cause cross-platform issues.
Quick fix
Fixes warning: path 'file.txt' contains non-UTF-8 characters
# List all tracked files and look for warnings
git ls-files
# Check the status to see warnings
git status- Identify the problematic files
- Configure Git to display non-ASCII characters properly
- Check your system locale settings
- Rename files with proper UTF-8 encoding
# List all tracked files and look for warningsgit ls-files# Check the status to see warningsgit statuswarning: path 'file.txt' contains non-UTF-8 characters
What this error means
Git expects path names (filenames and directory names) to be encoded in UTF-8 normalization form C. When Git encounters a filename that contains byte sequences that don't form valid UTF-8 characters, it displays this warning. At its core, Git treats path names as sequences of bytes rather than characters. However, Git's display utilities and many Git-based tools assume path names are UTF-8 encoded. When a filename contains bytes that represent characters in a different encoding (such as ISO-8859-1/Latin-1, Windows-1252, or other legacy encodings), Git cannot properly interpret or display the filename. This warning doesn't prevent Git from tracking the file, but it signals a potential portability problem. Repositories with non-UTF-8 filenames may work on the system where they were created but cause issues when cloned to systems with different locale settings. Many Git GUIs, web interfaces, and CI/CD systems will fail to display these filenames correctly or may fail to process them entirely.
Typical symptoms
- Git displays 'warning: path contains non-UTF-8 characters' during add, commit, or status operations
- Filenames appear as escaped octal sequences like '\303\251' instead of proper characters
- Git GUI clients or web interfaces display garbled characters in filenames
- Scripts or automation tools fail when processing filenames with special characters
- Cross-platform collaborators report different filename displays
- CI/CD pipelines fail when checking out or processing certain files
Common causes
- Files created on a system with a non-UTF-8 locale setting (most common)
- Filenames with accented characters (e.g., resume.txt, archivo.pdf) created with legacy encoding
- Files copied from Windows systems using Windows-1252 or other code pages
- Network shares or external drives formatted with non-UTF-8 filesystems
- Legacy repositories created before UTF-8 became the standard
- Terminal or shell environment configured with non-UTF-8 character encoding
How to fix "warning: path 'file.txt' contains non-UTF-8 characters"
First, find which files have non-UTF-8 characters in their names:
# List all tracked files and look for warnings
git ls-files
# Check the status to see warnings
git statusFiles with encoding issues will trigger warnings. You may also see filenames displayed as quoted octal sequences like "file\303\251.txt" instead of the actual characters.
To see the raw bytes of a filename:
# On Linux/macOS
ls -b
# Or use hexdump to see the actual bytes
ls | hexdump -CBy default, Git quotes non-ASCII characters in filenames. Disable this to see the actual characters:
# Stop quoting high-byte characters
git config --global core.quotePath falseThis won't fix the encoding issue, but it will display the characters as-is rather than as escaped sequences.
Additionally, ensure your Git environment uses UTF-8:
# Set commit and log output encoding
git config --global i18n.commitEncoding utf-8
git config --global i18n.logOutputEncoding utf-8Verify that your system is configured to use UTF-8:
On Linux:
# Check current locale
locale
# The LANG and LC_ALL should include UTF-8, like:
# LANG=en_US.UTF-8If not set to UTF-8, configure it:
# Set UTF-8 locale (add to ~/.bashrc or ~/.zshrc)
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8On macOS:
# Check current settings
locale
# Set in ~/.zshrc or ~/.bash_profile
export LANG=en_US.UTF-8On Windows Git Bash:
# Check current settings
echo $LANG
# Set in ~/.bashrc
export LANG=en_US.UTF-8The most reliable fix is to rename the files using proper UTF-8 encoding. First, use the convmv tool (Linux) to convert filenames:
# Install convmv (Debian/Ubuntu)
sudo apt-get install convmv
# Install convmv (macOS with Homebrew)
brew install convmv
# Preview what would change (dry run)
convmv -f iso-8859-1 -t utf-8 -r .
# Actually rename the files
convmv -f iso-8859-1 -t utf-8 -r --notest .Replace iso-8859-1 with the actual source encoding if different (common alternatives: windows-1252, cp437, latin1).
Manual rename approach:
# Remove the old file from Git
git rm --cached "oldfilename"
# Rename the file on the filesystem
mv "oldfilename" "newfilename_utf8"
# Add the renamed file
git add "newfilename_utf8"
# Commit the change
git commit -m "Rename file to use UTF-8 encoding"macOS uses a unique Unicode normalization (NFD - decomposed form) that can conflict with other systems using NFC (composed form). Git 1.7.12+ includes support for this:
# Enable Unicode precomposition for macOS
git config --global core.precomposeUnicode trueThis setting ensures Git normalizes Unicode characters consistently, preventing issues when sharing repositories between macOS and Linux/Windows.
If you're experiencing issues where filenames with accents appear differently on macOS vs other systems, this setting should resolve the discrepancy.
Git for Windows requires specific configuration for proper UTF-8 handling:
# Comprehensive UTF-8 configuration
git config --global core.quotePath false
git config --global i18n.commitEncoding utf-8
git config --global i18n.logOutputEncoding utf-8
git config --global gui.encoding utf-8Additionally, ensure your terminal supports UTF-8. In Git Bash, you can set:
# Add to ~/.bashrc
export LESSCHARSET=utf-8For PowerShell, set the output encoding:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8After renaming files or configuring Git, verify the warning is resolved:
# Check status - should show no encoding warnings
git status
# List files - should display properly without escaping
git ls-files
# View your configuration
git config --list | grep -E "(quote|i18n|precompose)"If you've renamed files, commit the changes:
git add -A
git commit -m "Fix non-UTF-8 filename encoding"Advanced notes
### Understanding Git's Path Encoding
Git internally stores path names as byte sequences, not as Unicode strings. The index file, tree objects, and ref names all use UTF-8 normalization form C (NFC). However, Git doesn't perform encoding conversions on paths at the core level (except on macOS and Windows for specific normalizations).
This means:
- A file named "cafe.txt" (with e-acute encoded in Latin-1) will have different bytes than the same visual filename encoded in UTF-8
- Git will track both as different files if both exist
- Many Git tools assume UTF-8 and will fail with other encodings
### Common Encoding Mismatches
| Source Encoding | Common On | Byte Example for "e" |
|----------------|-----------|---------------------|
| UTF-8 | Modern systems | c3 a9 |
| ISO-8859-1 (Latin-1) | Western European legacy | e9 |
| Windows-1252 | Windows applications | e9 |
| Mac Roman | Legacy macOS | 8c |
### Repository Migration Strategy
If you have a legacy repository with many non-UTF-8 filenames:
1. Clone on a system with the original encoding - Set your locale to match the encoding used when files were created
2. Use `convmv` to batch convert - Convert all filenames to UTF-8
3. Commit the renames - Create a single commit with all renames
4. Update `.gitattributes` - If needed, specify encodings for file contents (separate from filenames)
### BOM and .gitignore Files
Files like .gitignore, .gitattributes, and other Git configuration files must not have a UTF-8 BOM (Byte Order Mark). If your editor adds a BOM, Git may fail to parse these files correctly:
# Check for BOM
file .gitignore
# Should say "ASCII text" or "UTF-8 Unicode text", NOT "UTF-8 Unicode (with BOM)"
# Remove BOM if present (using sed)
sed -i '1s/^\xEF\xBB\xBF//' .gitignore### Cross-Platform Repositories
For teams working across different operating systems:
1. Standardize on UTF-8 for all filenames
2. Avoid special characters in filenames when possible
3. Use .gitattributes to enforce consistent line endings
4. Enable core.precomposeUnicode on macOS
5. Consider using ASCII-only filenames for maximum compatibility
Frequently asked questions
- What does "warning: path 'file.txt' contains non-UTF-8 characters" mean?
- Git expects path names (filenames and directory names) to be encoded in UTF-8 normalization form C. When Git encounters a filename that contains byte sequences that don't form valid UTF-8 characters, it displays this warning. At its core, Git treats path names as sequences of bytes rather than characters.
- How do I fix "warning: path 'file.txt' contains non-UTF-8 characters"?
- This Git warning appears when a filename contains characters that are not valid UTF-8 encoding. It commonly occurs with files created on systems using different character encodings (like Latin-1 or Windows code pages) and can cause cross-platform issues.
- What causes "warning: path 'file.txt' contains non-UTF-8 characters"?
- Files created on a system with a non-UTF-8 locale setting (most common) Filenames with accented characters (e.g., resume.txt, archivo.pdf) created with legacy encoding Files copied from Windows systems using Windows-1252 or other code pages
- Is the "warning: path 'file.txt' contains non-UTF-8 characters" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐Git FAQ - Path name encoding(Official Docs)
- ๐ฌ
- ๐ฌ
- ๐ฌGit not displaying unicode file names - Stack Overflow(Stack Overflow)
- ๐Git source code - utf8.c(GitHub)
- ๐