Reputation: 20080
I'm using Git-1.9.0-preview20140217
for Windows. As I know, this release should fix the issue with too long filenames. But not for me.
Surely I'm doing something wrong: I did git config core.longpaths true
and git add .
and then git commit
. Everything went well. But when I now do a git status
, I get a list of files with Filename too long
, for example:
node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js: Filename too long
It is quite simple to reproduce for me: just create a Yeoman web application with the Angular generator ("yo angular") and remove node_modules
from the .gitignore
file. Then repeat the aforementioned Git commands.
What am I missing here?
Upvotes: 1601
Views: 1519586
Reputation: 16900
On Windows:
Run as Administrator
)git config --system core.longpaths true
Note: if step 2 does not work or gives any error, you can also try running this command:
git config --global core.longpaths true
Read more about git config
here.
Upvotes: 286
Reputation: 19039
You can try to temporarily move the local repository (the entire folder) to the root of your drive or as close to the root as possible.
Since the path is smaller at the root of the drive, it sometimes fixes the issues.
On Windows, I'd move this to C:\
or another drive's root.
Upvotes: 8
Reputation: 139
Please follow the steps below to fix "Filename is too long" in Git.
git config --system core.longpaths true
"Upvotes: 0
Reputation: 378
This is worked for me on Windows:
Start-Process -Verb RunAs "git" "config","--global","core.longpaths","true"
Upvotes: 0
Reputation: 24431
Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename.
So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here: https://github.com/msysgit/git/pull/110
You can circumvent this by using another Git client on Windows or set core.longpaths
to true
as explained in other answers.
git config --system core.longpaths true
NOTE: due to https://github.com/desktop/desktop/issues/8023#issuecomment-515115353, Github Desktop (and potentially other Git GUIs as well) will read the --global
config but not the --system
config
Git is build as a combination of scripts and compiled code. With the above change some of the scripts might fail. That's the reason for core.longpaths not to be enabled by default.
The windows documentation at https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later has some more information:
Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.
A registry key allows you to enable or disable the new long path behavior. To enable long path behavior set the registry key at HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD)
This is a Windows specific issue, hence the solution below should work in most Windows versions, new and old.
Open a PowerShell window/console, and run the following:
# Check LongPathsEnabled settings
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled
# If 0, set it to 1 - This is a System wide configuration
# This will fail if you do not have Admin priveleges
# Changes to CurrentControlSet\Control take effect after a system restart
$MyPSexe = Get-Process -PID $PID | % Path
Start-Process -Verb RunAs $MyPSexe "-c","Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Type DWord -Value 1"
git config --system
- System wide for all Windows users:Start-Process -Verb RunAs "git" "config","--system","core.longpaths","true"
git config --global
- User's global settings:& git config "--global" core.longpaths true
Upvotes: 2345
Reputation: 13427
You should be able to run the command
git config --system core.longpaths true
from an Administrator command prompt.
Or add it to one of your Git configuration files manually to turn this functionality on, once you are on a supported version of Git. It looks like maybe 1.9.0 and after.
Upvotes: 1330
Reputation: 1715
git config --system core.longpaths true
git config --global core.longpaths true
Upvotes: 21
Reputation: 566
This worked for me
Run as terminal as administrator. And run the command below.
git config --system core.longpaths true
Upvotes: 43
Reputation: 5787
This might help:
git config core.longpaths true
Basic explanation: This answer suggests not to have such setting applied to the global system (to all projects so avoiding --system
or --global
tag) configurations. This command only solves the problem by being specific to the current project.
EDIT:
This is an important answer related to the "permission denied" issue for those whom does not granted to change git settings globally.
Upvotes: 392
Reputation: 2110
For anyone using TortoiseGit for Windows, I did this:
(1) Right-click on the folder containing your project. Select TortoiseGit -> Settings.
(2) On the "Git" tab, click the button to "Edit local .git/config".
(3) In the text file that pops up, under the [core] section, add: longpaths = true
Save and close everything, then re-try your commit. For me, this worked.
I hope this minimizes any possible system-wide issues, since we are not editing the global .gitconfig file, but rather just the one for this particular repository.
Upvotes: 15
Reputation: 3801
In Windows, you can follow these steps which worked for me.
git config --system core.longpaths true
This will allow accessing long paths globally
And now you can clone the repository with no issues with long paths
Upvotes: 8
Reputation: 1013
Run Command Prompt as administrator then run below command
git config --system core.longpaths true
Upvotes: 3
Reputation: 4172
git config --global core.longpaths true
The above command worked for me. Using '--system' gave me config file not locked error
Upvotes: 18
Reputation: 29316
Executing git config --system core.longpaths true
thrown an error to me:
"error: could not lock config file C:\Program Files (x86)\Git\mingw32/etc/gitconfig: Permission denied"
Fixed with executing the command at the global level:
git config --global core.longpaths true
Upvotes: 36
Reputation: 1780
You could also try to enable long file paths.
If you run Windows 10 Home Edition you could change your Registry to enable long paths.
Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
in regedit
and then set LongPathsEnabled
to 1
.
If you have Windows 10 Pro or Enterprise you could also use Local Group Policies.
Go to Computer Configuration → Administrative Templates → System → Filesystem in gpedit.msc
, open Enable Win32 long paths and set it to Enabled.
Upvotes: 19
Reputation: 382
If you are working with your encrypted partition, consider moving the folder to an unencrypted partition, for example a /tmp, running git pull
, and then moving back.
Upvotes: 1
Reputation: 1817
The better solution is enable the longpath parameter from Git.
git config --system core.longpaths true
But a workaround that works is remove the node_modules folder from Git:
$ git rm -r --cached node_modules
$ vi .gitignore
Add node_modules in a new row inside the .gitignore file. After doing this, push your modifications:
$ git add .gitignore
$ git commit -m "node_modules removed"
$ git push
Upvotes: 39
Reputation: 7064
Create .gitconfig and add
[core]
longpaths = true
You can create the file in a project location (not sure) and also in the global location. In my case the location is C:\Users\{name}\
.
Upvotes: 139
Reputation: 1837
I had this error too, but in my case the cause was using an outdated version of npm, v1.4.28.
Updating to npm v3 followed by
rm -rf node_modules
npm -i
worked for me. npm issue 2697 has details of the "maximally flat" folder structure included in npm v3 (released 2015-06-25).
Upvotes: 2
Reputation: 5308
To be entirely sure that it takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out, it is safer to use it this way:
git clone -c core.longpaths=true <repo-url>
-c key=value
Set a configuration variable in the newly-created repository; this takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out. The key is in the same format as expected by git-config1 (e.g., core.eol=true). If multiple values are given for the same key, each value will be written to the config file. This makes it safe, for example, to add additional fetch refspecs to the origin remote.
Upvotes: 68