When working with Git repositories, you may encounter the "filename too long" error during clone operations. This error occurs due to path length limitations in different operating systems. This guide will show you how to resolve this issue on both Windows and Linux systems.

By following this guide, you'll be able to successfully clone repositories that contain long filenames and continue with your development work.

Prerequisites

  • Git installed on your system
  • Administrator/root access to modify system configurations
  • Basic command line knowledge
  • A Git repository to clone

Identifying the Problem

The error typically appears in one of these forms:

error: unable to create file <long_path>: Filename too long

error: invalid path '<long_path>'

Solution for Windows

Method 1: Enable Long Paths in Windows and Git

  1. Enable long path support in Windows by running PowerShell as Administrator and executing:
PS> New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

2. Configure Git to handle long paths:

git config — global core.longpaths true

3. Restart your computer for changes to take effect.

Method 2: Using Git Bash with Core.LongPaths

If you prefer not to modify Windows settings, you can configure Git Bash:

  1. Open Git Bash as Administrator
  2. Set the core.longpaths configuration:
git config — global core.longpaths true

Solution for Linux

  • Check your Git version:
git - version
  • Configure Git to handle long paths:
git config — global core.longpaths true

Method 2: Using a Shorter Target Directory

If you continue experiencing issues, try cloning to a shorter path:

  • Navigate to a directory with a short path:
cd /tmp
  • Clone your repository:
git clone <repository_url>
  • Move the repository to your desired location:
 mv /tmp/<repository_name> <your_desired_path>

Troubleshooting Common Issues

Issue: Windows Error Persists After Configuration

If you still encounter errors after enabling long paths:

  • Verify the registry setting:
PS> Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled"
  • Check Git configuration:
git config — list | grep longpaths

Issue: Permission Denied When Modifying Settings

If you receive "permission denied" errors:

1. Ensure you're running as Administrator (Windows) or using sudo (Linux)

2. Check file permissions on the Git configuration file

Next Steps and References

After successfully resolving the long filename issue, you may want to:

1. Set up Git aliases to improve workflow efficiency

2. Configure Git credential management

3. Learn about Git submodules for managing long directory structures

Additional Resources