Pages

Monday, April 6, 2020

3 Ways to Fix Git Clone "Filename too long" Error in Windows [Fixed]

1. Introduction


In this tutorial, We'll learn how to fix the git clone error "Filename too long" in windows operating systems Powershell and GitHub Application. This happens when doing a git clone from remote repositories.

Most used Git Commands

This error does not come for the UNIX or mac users. So they can push the long length file names to git but the issues occur only for the windows users. Because this capability is disabled by default in the Windows operating system.

Usually, 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.


3 Ways to Fix git "Filename too long" Error in Windows [Fixed]




2. Filename too long - Solution 1 - Git Global Level


Follow the steps below to fix "Filename is too long" in git.


  • Update the git version to the latest from here. If you have updated, ignore this step.
  • Navigate to your project folder
  • Open the Git Bash and run as administrator
  • To enable the long paths to run "git config core.longpaths true" in git bash


Now clone the project that has long file names that should not produce such error now.

This is a solution that works for all the times and no one reported after applying this solution. This works for all the repositories which will be clone in future projects.

3. Filename too long - Solution 2 - Git specific project


If you have clone already project into local machine and while getting new changes using the "git pull" command, it will produce the git filenames are too long error.

To apply the fix only to this project, just go to the project home directory and find the ".git" folder.

Open the config file and look at the [core] section. At the end of this section add longpaths to true as "longpaths = true".

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    longpaths = true

This fix works only for this repo.

4. Git Filename too long - Solution 3 - Through Git Clone Command


If you want to fix this while cloning the repository, there is an option to do as part of the "git clone" command. First to enable flags to accept with the option "-c" and next pass core.longpaths=true as below.

git clone -c core.longpaths=true 

5. Conclusion


In this article, We've seen how to fix the common git error 'git filename too long' which comes into existence working with windows. Shown 3 ways to fix this error.

References:

Stackoverflow 1

Stackoverflow 2

2 comments:

Please do not add any spam links in the comments section.